@@ -75,6 +75,8 @@ public function workspace_hygiene_report( array $opts = array() ): array|\WP_Err
7575 $ cleanup = null ;
7676 }
7777 }
78+ $ worktree_summary = $ this ->summarize_workspace_worktrees ( $ worktrees , $ cleanup );
79+
7880 return array (
7981 'success ' => true ,
8082 'generated_at ' => gmdate ( 'c ' ),
@@ -86,7 +88,7 @@ public function workspace_hygiene_report( array $opts = array() ): array|\WP_Err
8688 'freshness ' => $ this ->worktree_inventory ()->freshness (),
8789 'refresh ' => $ inventory_refresh ,
8890 ),
89- 'worktrees ' => $ this -> summarize_workspace_worktrees ( $ worktrees , $ cleanup ) ,
91+ 'worktrees ' => $ worktree_summary ,
9092 'worktree_status_mode ' => $ worktree_status_mode ,
9193 'top_repos_by_worktrees ' => $ this ->top_repos_by_worktree_count ( $ worktrees , 10 ),
9294 'top_repos_by_size ' => $ this ->top_repos_by_size ( (array ) ( $ size_report ['entries ' ] ?? array () ), 10 ),
@@ -97,6 +99,7 @@ public function workspace_hygiene_report( array $opts = array() ): array|\WP_Err
9799 $ include_sizes ? (string ) ( $ size_report ['mode_note ' ] ?? '' ) : 'Size scan disabled by request. ' ,
98100 $ include_worktree_status ? 'Full worktree status enabled; this may run git status across every worktree. ' : 'Worktree status uses cheap top-level inventory; pass --include-worktree-status for full git status. ' ,
99101 $ include_cleanup ? 'Cleanup summary uses inventory-only dry-run detection (--inventory-only --skip-github); no per-worktree git probes or GitHub API lookups are required. ' : 'Cleanup dry-run disabled by request. ' ,
102+ ! empty ( $ worktree_summary ['base_branch_worktree_count ' ] ) ? 'One or more non-primary worktrees have a base branch checked out; gh pr merge --delete-branch can merge remotely but fail local cleanup. ' : '' ,
100103 ) ) ),
101104 );
102105 }
@@ -342,14 +345,15 @@ private function build_workspace_inventory_rows(): array {
342345 $ session_view = WorktreeContextInjector::summarize_session ( is_array ( $ metadata ) ? $ metadata : null );
343346 $ task_view = is_array ( $ metadata ) && is_array ( $ metadata ['origin_task ' ] ?? null ) ? $ metadata ['origin_task ' ] : null ;
344347
345- $ rows [] = array (
348+ $ row = array (
346349 'handle ' => $ parsed ['dir_name ' ],
347350 'repo ' => $ parsed ['repo ' ],
348351 'kind ' => $ kind ,
349352 'is_worktree ' => $ is_worktree ,
350353 'is_primary ' => 'primary ' === $ kind ,
351354 'external ' => false ,
352355 'branch_slug ' => $ parsed ['branch_slug ' ],
356+ 'branch ' => is_array ( $ metadata ) && ! empty ( $ metadata ['branch ' ] ) ? (string ) $ metadata ['branch ' ] : (string ) ( $ parsed ['branch_slug ' ] ?? '' ),
353357 'path ' => $ path ,
354358 'dirty ' => 0 ,
355359 'created_at ' => is_array ( $ metadata ) ? ( $ metadata ['created_at ' ] ?? null ) : null ,
@@ -366,6 +370,13 @@ private function build_workspace_inventory_rows(): array {
366370 'missing_metadata ' => $ is_worktree && ! is_array ( $ metadata ),
367371 'metadata ' => $ metadata ,
368372 );
373+
374+ $ base_branch_warning = $ this ->base_branch_worktree_warning ( $ row );
375+ if ( null !== $ base_branch_warning ) {
376+ $ row ['base_branch_warning ' ] = $ base_branch_warning ;
377+ }
378+
379+ $ rows [] = $ row ;
369380 }
370381
371382 return $ rows ;
@@ -523,6 +534,8 @@ private function summarize_workspace_worktrees( array $worktrees, ?array $cleanu
523534 'protected_dirty ' => 0 ,
524535 'protected_unpushed ' => 0 ,
525536 'missing_metadata ' => 0 ,
537+ 'base_branch_worktree_count ' => 0 ,
538+ 'base_branch_worktrees ' => array (),
526539 'by_liveness ' => array (
527540 WorktreeContextInjector::LIVENESS_LIVE => 0 ,
528541 WorktreeContextInjector::LIVENESS_STOPPED => 0 ,
@@ -553,6 +566,11 @@ private function summarize_workspace_worktrees( array $worktrees, ?array $cleanu
553566 ++$ summary ['missing_metadata ' ];
554567 }
555568
569+ if ( ! empty ( $ row ['base_branch_warning ' ] ) && is_array ( $ row ['base_branch_warning ' ] ) ) {
570+ ++$ summary ['base_branch_worktree_count ' ];
571+ $ summary ['base_branch_worktrees ' ][] = $ row ['base_branch_warning ' ];
572+ }
573+
556574 if ( ! empty ( $ row ['is_worktree ' ] ) ) {
557575 $ liveness = (string ) ( $ row ['liveness ' ] ?? WorktreeContextInjector::LIVENESS_UNKNOWN );
558576 if ( ! isset ( $ summary ['by_liveness ' ][ $ liveness ] ) ) {
0 commit comments