@@ -299,7 +299,18 @@ fn render_change(change: &FileChange, out: &mut Vec<RtLine<'static>>, width: usi
299299 }
300300}
301301
302+ /// Format a path for display relative to the current working directory when
303+ /// possible, keeping output stable in jj/no-`.git` workspaces (e.g. image
304+ /// tool calls should show `example.png` instead of an absolute path).
302305pub ( crate ) fn display_path_for ( path : & Path , cwd : & Path ) -> String {
306+ if path. is_relative ( ) {
307+ return path. display ( ) . to_string ( ) ;
308+ }
309+
310+ if let Ok ( stripped) = path. strip_prefix ( cwd) {
311+ return stripped. display ( ) . to_string ( ) ;
312+ }
313+
303314 // Prefer a stable, user-local relative path when the file is under the current working
304315 // directory. This keeps output deterministic in jj-only repos (no `.git`) and matches user
305316 // expectations for "files in this project".
@@ -431,6 +442,7 @@ fn style_del() -> Style {
431442mod tests {
432443 use super :: * ;
433444 use insta:: assert_snapshot;
445+ use pretty_assertions:: assert_eq;
434446 use ratatui:: Terminal ;
435447 use ratatui:: backend:: TestBackend ;
436448 use ratatui:: text:: Text ;
@@ -470,6 +482,26 @@ mod tests {
470482 assert_snapshot ! ( name, text) ;
471483 }
472484
485+ #[ test]
486+ fn display_path_prefers_cwd_without_git_repo ( ) {
487+ let cwd = if cfg ! ( windows) {
488+ PathBuf :: from ( r"C:\workspace\codex" )
489+ } else {
490+ PathBuf :: from ( "/workspace/codex" )
491+ } ;
492+ let path = cwd. join ( "tui" ) . join ( "example.png" ) ;
493+
494+ let rendered = display_path_for ( & path, & cwd) ;
495+
496+ assert_eq ! (
497+ rendered,
498+ PathBuf :: from( "tui" )
499+ . join( "example.png" )
500+ . display( )
501+ . to_string( )
502+ ) ;
503+ }
504+
473505 #[ test]
474506 fn ui_snapshot_wrap_behavior_insert ( ) {
475507 // Narrow width to force wrapping within our diff line rendering
0 commit comments