@@ -477,117 +477,30 @@ public function worktree_cleanup_merged( array $opts = array() ): array|\WP_Erro
477477 if ( null === $ signal ) {
478478 $ signal = $ this ->detect_merge_signal ($ primary_path , $ repo , $ branch , $ skip_github , $ github_cache );
479479 }
480- if ( null === $ signal ) {
481- $ skipped [] = array_merge (
482- array (
483- 'handle ' => $ handle ,
484- 'repo ' => $ repo ,
485- 'branch ' => $ branch ,
486- 'path ' => $ wt_path ,
487- 'reason_code ' => 'no_merge_signal ' ,
488- 'reason ' => 'no merge signal — leaving in place ' ,
489- 'merge_signal_evidence ' => $ this ->build_no_merge_signal_evidence ($ primary_path , $ branch , $ skip_github ),
490- 'active_review_command ' => 'studio wp datamachine-code workspace worktree active-no-signal-report --limit=25 --offset=0 --format=json ' ,
491- 'active_review_commands ' => $ this ->build_active_no_signal_next_commands (25 , 0 ),
492- 'created_at ' => $ created_at ,
493- 'metadata ' => $ metadata ,
494- ), $ disk_fields
495- );
496- continue ;
497- }
498-
499- if ( 'probe-timeout ' === $ signal ['signal ' ] ) {
500- $ skipped [] = array_merge (
501- array (
502- 'handle ' => $ handle ,
503- 'repo ' => $ repo ,
504- 'branch ' => $ branch ,
505- 'path ' => $ wt_path ,
506- 'reason_code ' => 'probe_timeout ' ,
507- 'reason ' => $ signal ['reason ' ],
508- 'created_at ' => $ created_at ,
509- 'metadata ' => $ metadata ,
510- ), $ disk_fields
511- );
512- continue ;
513- }
480+ $ classification = WorktreeCleanupCandidateClassifier::classify_merge_signal_path (
481+ array (
482+ 'handle ' => $ handle ,
483+ 'repo ' => $ repo ,
484+ 'branch ' => $ branch ,
485+ 'path ' => $ wt_path ,
486+ 'dirty_count ' => $ dirty_count ,
487+ 'created_at ' => $ created_at ,
488+ 'liveness ' => $ liveness ,
489+ 'metadata ' => $ metadata ,
490+ 'disk_fields ' => $ disk_fields ,
491+ ),
492+ $ signal ,
493+ $ age_filter ,
494+ fn () => $ this ->build_no_merge_signal_evidence ($ primary_path , $ branch , $ skip_github ),
495+ $ this ->build_active_no_signal_next_commands (25 , 0 )
496+ );
514497
515- if ( 'github-unknown ' === $ signal ['signal ' ] ) {
516- $ skipped [] = array_merge (
517- array (
518- 'handle ' => $ handle ,
519- 'repo ' => $ repo ,
520- 'branch ' => $ branch ,
521- 'path ' => $ wt_path ,
522- 'reason_code ' => 'github_unknown ' ,
523- 'reason ' => $ signal ['reason ' ],
524- 'merge_signal_evidence ' => array (
525- 'classification ' => 'github_signal_unavailable ' ,
526- 'github_signal ' => 'unavailable ' ,
527- 'reason ' => $ signal ['reason ' ],
528- ),
529- 'active_review_command ' => 'studio wp datamachine-code workspace worktree active-no-signal-report --limit=25 --offset=0 --format=json ' ,
530- 'active_review_commands ' => $ this ->build_active_no_signal_next_commands (25 , 0 ),
531- 'created_at ' => $ created_at ,
532- 'metadata ' => $ metadata ,
533- ), $ disk_fields
534- );
498+ if ( 'candidate ' === $ classification ['type ' ] ) {
499+ $ candidates [] = $ classification ['row ' ];
535500 continue ;
536501 }
537502
538- $ age_decision = null ;
539- if ( null !== $ age_filter ) {
540- $ age_decision = WorktreeAgeFilter::decide ($ created_at , $ age_filter );
541- if ( 'unknown_age ' === $ age_decision ['decision ' ] ) {
542- $ skipped [] = array_merge (
543- array (
544- 'handle ' => $ handle ,
545- 'repo ' => $ repo ,
546- 'branch ' => $ branch ,
547- 'path ' => $ wt_path ,
548- 'created_at ' => $ created_at ,
549- 'metadata ' => $ metadata ,
550- ),
551- WorktreeAgeFilter::skip_fields ($ age_decision ),
552- $ disk_fields
553- );
554- continue ;
555- }
556-
557- if ( 'excluded ' === $ age_decision ['decision ' ] ) {
558- $ skipped [] = array_merge (
559- array (
560- 'handle ' => $ handle ,
561- 'repo ' => $ repo ,
562- 'branch ' => $ branch ,
563- 'path ' => $ wt_path ,
564- 'created_at ' => $ created_at ,
565- 'metadata ' => $ metadata ,
566- ),
567- WorktreeAgeFilter::skip_fields ($ age_decision ),
568- $ disk_fields
569- );
570- continue ;
571- }
572- }
573-
574- $ candidate = array_merge (
575- array (
576- 'handle ' => $ wt ['handle ' ],
577- 'repo ' => $ repo ,
578- 'branch ' => $ branch ,
579- 'path ' => $ wt_path ,
580- 'dirty ' => $ dirty_count ,
581- 'cleanup_reasons ' => array_values (array_filter (array ( $ signal ['signal ' ], $ signal ['reason ' ] ))),
582- 'created_at ' => $ created_at ,
583- 'liveness ' => $ liveness ,
584- 'metadata ' => $ metadata ,
585- ), WorktreeCleanupSignal::candidate_fields ($ signal , true ), $ disk_fields
586- );
587- if ( null !== $ age_decision ) {
588- $ candidate ['age_filter ' ] = $ age_decision ['age_filter ' ];
589- }
590- $ candidates [] = $ candidate ;
503+ $ skipped [] = $ classification ['row ' ];
591504 }
592505
593506 $ candidates = $ this ->dedupe_worktree_cleanup_rows ($ candidates );
0 commit comments