@@ -284,13 +284,13 @@ private function build_cleanup_plan_summary( array $rows, array $artifact_plan =
284284 $ category_total = array_sum (array_map ('intval ' , $ category_totals ));
285285
286286 return array (
287- 'total_rows ' => $ total_rows ,
288- 'rows_by_type ' => $ counts ,
289- 'byte_totals ' => $ byte_totals ,
290- 'total_size_bytes ' => $ category_total > 0 ? $ category_total : $ total_bytes ,
291- 'category_totals ' => $ category_totals ,
292- 'top_reclaimable ' => $ this ->cleanup_plan_top_reclaimable_paths ($ rows , (int ) ( $ inputs ['top_n ' ] ?? 10 )),
293- 'blockers ' => $ this ->cleanup_plan_blockers ($ artifact_plan , $ worktree_plan ),
287+ 'total_rows ' => $ total_rows ,
288+ 'rows_by_type ' => $ counts ,
289+ 'byte_totals ' => $ byte_totals ,
290+ 'total_size_bytes ' => $ category_total > 0 ? $ category_total : $ total_bytes ,
291+ 'category_totals ' => $ category_totals ,
292+ 'top_reclaimable ' => $ this ->cleanup_plan_top_reclaimable_paths ($ rows , (int ) ( $ inputs ['top_n ' ] ?? 10 )),
293+ 'blockers ' => $ this ->cleanup_plan_blockers ($ artifact_plan , $ worktree_plan ),
294294 'recommended_commands ' => $ this ->cleanup_plan_recommended_commands ($ inputs ),
295295 );
296296 }
@@ -303,10 +303,10 @@ private function build_cleanup_plan_summary( array $rows, array $artifact_plan =
303303 */
304304 private function cleanup_plan_category_totals ( array $ rows ): array {
305305 $ totals = array (
306- 'whole_worktrees ' => 0 ,
307- 'dependency_artifacts ' => 0 ,
308- 'build_outputs ' => 0 ,
309- 'caches ' => 0 ,
306+ 'whole_worktrees ' => 0 ,
307+ 'dependency_artifacts ' => 0 ,
308+ 'build_outputs ' => 0 ,
309+ 'caches ' => 0 ,
310310 );
311311
312312 foreach ( (array ) ( $ rows ['worktree_removal ' ] ?? array () ) as $ row ) {
@@ -320,7 +320,7 @@ private function cleanup_plan_category_totals( array $rows ): array {
320320 if ( ! is_array ($ artifact ) ) {
321321 continue ;
322322 }
323- $ category = $ this ->cleanup_artifact_category ( (string ) ( $ artifact ['path ' ] ?? '' ));
323+ $ category = $ this ->cleanup_artifact_category ( (string ) ( $ artifact ['path ' ] ?? '' ));
324324 $ totals [ $ category ] += max (0 , (int ) ( $ artifact ['size_bytes ' ] ?? 0 ));
325325 }
326326 }
@@ -361,13 +361,13 @@ private function cleanup_plan_top_reclaimable_paths( array $rows, int $limit ):
361361 continue ;
362362 }
363363 $ paths [] = array (
364- 'path ' => (string ) ( $ row ['path ' ] ?? '' ),
365- 'handle ' => (string ) ( $ row ['handle ' ] ?? '' ),
366- 'repo ' => (string ) ( $ row ['repo ' ] ?? '' ),
367- 'category ' => 'whole_worktrees ' ,
368- 'row_type ' => 'worktree_removal ' ,
369- 'safety_class ' => (string ) ( $ row ['safety_class ' ] ?? 'reviewed_destructive ' ),
370- 'size_bytes ' => max (0 , (int ) ( $ row ['size_bytes ' ] ?? 0 )),
364+ 'path ' => (string ) ( $ row ['path ' ] ?? '' ),
365+ 'handle ' => (string ) ( $ row ['handle ' ] ?? '' ),
366+ 'repo ' => (string ) ( $ row ['repo ' ] ?? '' ),
367+ 'category ' => 'whole_worktrees ' ,
368+ 'row_type ' => 'worktree_removal ' ,
369+ 'safety_class ' => (string ) ( $ row ['safety_class ' ] ?? 'reviewed_destructive ' ),
370+ 'size_bytes ' => max (0 , (int ) ( $ row ['size_bytes ' ] ?? 0 )),
371371 );
372372 }
373373
@@ -380,13 +380,13 @@ private function cleanup_plan_top_reclaimable_paths( array $rows, int $limit ):
380380 continue ;
381381 }
382382 $ paths [] = array (
383- 'path ' => (string ) ( $ artifact ['path ' ] ?? '' ),
384- 'handle ' => (string ) ( $ row ['handle ' ] ?? '' ),
385- 'repo ' => (string ) ( $ row ['repo ' ] ?? '' ),
386- 'category ' => $ this ->cleanup_artifact_category ( (string ) ( $ artifact ['path ' ] ?? '' )),
387- 'row_type ' => 'artifact_cleanup ' ,
388- 'safety_class ' => (string ) ( $ row ['safety_class ' ] ?? 'safe ' ),
389- 'size_bytes ' => max (0 , (int ) ( $ artifact ['size_bytes ' ] ?? 0 )),
383+ 'path ' => (string ) ( $ artifact ['path ' ] ?? '' ),
384+ 'handle ' => (string ) ( $ row ['handle ' ] ?? '' ),
385+ 'repo ' => (string ) ( $ row ['repo ' ] ?? '' ),
386+ 'category ' => $ this ->cleanup_artifact_category ( (string ) ( $ artifact ['path ' ] ?? '' )),
387+ 'row_type ' => 'artifact_cleanup ' ,
388+ 'safety_class ' => (string ) ( $ row ['safety_class ' ] ?? 'safe ' ),
389+ 'size_bytes ' => max (0 , (int ) ( $ artifact ['size_bytes ' ] ?? 0 )),
390390 );
391391 }
392392 }
@@ -404,7 +404,10 @@ private function cleanup_plan_top_reclaimable_paths( array $rows, int $limit ):
404404 */
405405 private function cleanup_plan_blockers ( array $ artifact_plan , array $ worktree_plan ): array {
406406 $ blockers = array ();
407- foreach ( array ( 'artifact_cleanup ' => $ artifact_plan , 'worktree_removal ' => $ worktree_plan ) as $ type => $ plan ) {
407+ foreach ( array (
408+ 'artifact_cleanup ' => $ artifact_plan ,
409+ 'worktree_removal ' => $ worktree_plan ,
410+ ) as $ type => $ plan ) {
408411 foreach ( (array ) ( $ plan ['skipped ' ] ?? array () ) as $ row ) {
409412 if ( ! is_array ($ row ) ) {
410413 continue ;
@@ -414,21 +417,21 @@ private function cleanup_plan_blockers( array $artifact_plan, array $worktree_pl
414417 if ( '' === $ repo ) {
415418 $ repo = 'unknown ' ;
416419 }
417- $ bytes = max (0 , (int ) ( $ row ['artifact_size_bytes ' ] ?? $ row ['size_bytes ' ] ?? 0 ));
418- $ blockers [ $ reason ] ??= array (
420+ $ bytes = max (0 , (int ) ( $ row ['artifact_size_bytes ' ] ?? $ row ['size_bytes ' ] ?? 0 ));
421+ $ blockers [ $ reason ] ??= array (
419422 'count ' => 0 ,
420423 'size_bytes ' => 0 ,
421424 'repos ' => array (),
422425 'examples ' => array (),
423426 );
424- $ blockers [ $ reason ]['count ' ] = (int ) $ blockers [ $ reason ]['count ' ] + 1 ;
425- $ blockers [ $ reason ]['size_bytes ' ] += $ bytes ;
427+ $ blockers [ $ reason ]['count ' ] = (int ) $ blockers [ $ reason ]['count ' ] + 1 ;
428+ $ blockers [ $ reason ]['size_bytes ' ] += $ bytes ;
426429 $ blockers [ $ reason ]['repos ' ][ $ repo ] ??= array (
427430 'count ' => 0 ,
428431 'size_bytes ' => 0 ,
429432 'examples ' => array (),
430433 );
431- $ blockers [ $ reason ]['repos ' ][ $ repo ]['count ' ] = (int ) $ blockers [ $ reason ]['repos ' ][ $ repo ]['count ' ] + 1 ;
434+ $ blockers [ $ reason ]['repos ' ][ $ repo ]['count ' ] = (int ) $ blockers [ $ reason ]['repos ' ][ $ repo ]['count ' ] + 1 ;
432435 $ blockers [ $ reason ]['repos ' ][ $ repo ]['size_bytes ' ] += $ bytes ;
433436 if ( count ($ blockers [ $ reason ]['examples ' ]) < 5 ) {
434437 $ blockers [ $ reason ]['examples ' ][] = (string ) ( $ row ['handle ' ] ?? $ row ['path ' ] ?? '' );
@@ -439,9 +442,21 @@ private function cleanup_plan_blockers( array $artifact_plan, array $worktree_pl
439442 }
440443 }
441444
442- uasort ($ blockers , fn ( $ a , $ b ) => (int ) ( $ b ['size_bytes ' ] ?? 0 ) <=> (int ) ( $ a ['size_bytes ' ] ?? 0 ) ?: (int ) ( $ b ['count ' ] ?? 0 ) <=> (int ) ( $ a ['count ' ] ?? 0 ));
445+ uasort ($ blockers , function ( $ a , $ b ): int {
446+ $ size_compare = (int ) ( $ b ['size_bytes ' ] ?? 0 ) <=> (int ) ( $ a ['size_bytes ' ] ?? 0 );
447+ if ( 0 !== $ size_compare ) {
448+ return $ size_compare ;
449+ }
450+ return (int ) ( $ b ['count ' ] ?? 0 ) <=> (int ) ( $ a ['count ' ] ?? 0 );
451+ });
443452 foreach ( $ blockers as &$ bucket ) {
444- uasort ($ bucket ['repos ' ], fn ( $ a , $ b ) => (int ) ( $ b ['size_bytes ' ] ?? 0 ) <=> (int ) ( $ a ['size_bytes ' ] ?? 0 ) ?: (int ) ( $ b ['count ' ] ?? 0 ) <=> (int ) ( $ a ['count ' ] ?? 0 ));
453+ uasort ($ bucket ['repos ' ], function ( $ a , $ b ): int {
454+ $ size_compare = (int ) ( $ b ['size_bytes ' ] ?? 0 ) <=> (int ) ( $ a ['size_bytes ' ] ?? 0 );
455+ if ( 0 !== $ size_compare ) {
456+ return $ size_compare ;
457+ }
458+ return (int ) ( $ b ['count ' ] ?? 0 ) <=> (int ) ( $ a ['count ' ] ?? 0 );
459+ });
445460 }
446461 unset($ bucket );
447462
@@ -457,28 +472,28 @@ private function cleanup_plan_blockers( array $artifact_plan, array $worktree_pl
457472 private function cleanup_plan_recommended_commands ( array $ inputs ): array {
458473 $ commands = array (
459474 array (
460- 'label ' => 'apply_reviewed_plan ' ,
461- 'risk ' => 'reviewed_destructive ' ,
462- 'command ' => 'studio wp datamachine-code workspace cleanup apply <run-id> ' ,
463- 'when ' => 'after reviewing this plan; revalidates every destructive row before removal ' ,
475+ 'label ' => 'apply_reviewed_plan ' ,
476+ 'risk ' => 'reviewed_destructive ' ,
477+ 'command ' => 'studio wp datamachine-code workspace cleanup apply <run-id> ' ,
478+ 'when ' => 'after reviewing this plan; revalidates every destructive row before removal ' ,
464479 ),
465480 array (
466- 'label ' => 'inspect_full_plan_json ' ,
467- 'risk ' => 'none ' ,
468- 'command ' => 'studio wp datamachine-code workspace cleanup plan --mode=retention --format=json ' ,
469- 'when ' => 'export the full plan for review or archival ' ,
481+ 'label ' => 'inspect_full_plan_json ' ,
482+ 'risk ' => 'none ' ,
483+ 'command ' => 'studio wp datamachine-code workspace cleanup plan --mode=retention --format=json ' ,
484+ 'when ' => 'export the full plan for review or archival ' ,
470485 ),
471486 array (
472- 'label ' => 'resolve_metadata_blockers ' ,
473- 'risk ' => 'none ' ,
474- 'command ' => 'studio wp datamachine-code workspace worktree reconcile-metadata --dry-run --limit=25 --offset=0 --until-budget=30s --format=json ' ,
475- 'when ' => 'metadata blockers prevent classification ' ,
487+ 'label ' => 'resolve_metadata_blockers ' ,
488+ 'risk ' => 'none ' ,
489+ 'command ' => 'studio wp datamachine-code workspace worktree reconcile-metadata --dry-run --limit=25 --offset=0 --until-budget=30s --format=json ' ,
490+ 'when ' => 'metadata blockers prevent classification ' ,
476491 ),
477492 array (
478- 'label ' => 'refresh_merge_signals ' ,
479- 'risk ' => 'none ' ,
480- 'command ' => 'studio wp datamachine-code workspace worktree cleanup --dry-run --format=json ' ,
481- 'when ' => 'active or lifecycle rows need full merge/PR signal review ' ,
493+ 'label ' => 'refresh_merge_signals ' ,
494+ 'risk ' => 'none ' ,
495+ 'command ' => 'studio wp datamachine-code workspace worktree cleanup --dry-run --format=json ' ,
496+ 'when ' => 'active or lifecycle rows need full merge/PR signal review ' ,
482497 ),
483498 );
484499
0 commit comments