@@ -1562,29 +1562,33 @@ private function registerAbilities(): void {
15621562 'input_schema ' => array (
15631563 'type ' => 'object ' ,
15641564 'properties ' => array (
1565- 'mode ' => array (
1565+ 'mode ' => array (
15661566 'type ' => 'string ' ,
1567- 'description ' => 'Cleanup mode: inventory, artifacts, retention, or emergency. ' ,
1567+ 'description ' => 'Cleanup mode: inventory, artifacts, retention, stale-worktrees, or emergency. ' ,
15681568 ),
1569- 'force ' => array (
1569+ 'force ' => array (
15701570 'type ' => 'boolean ' ,
15711571 'description ' => 'Forward force=true to cleanup tasks that support it. ' ,
15721572 ),
1573- 'dry_run ' => array (
1573+ 'dry_run ' => array (
15741574 'type ' => 'boolean ' ,
15751575 'description ' => 'Rejected for background cleanup scheduling; use review abilities for dry-runs. ' ,
15761576 ),
1577- 'older_than ' => array (
1577+ 'older_than ' => array (
15781578 'type ' => 'string ' ,
15791579 'description ' => 'Optional worktree retention age gate such as 14d. ' ,
15801580 ),
1581- 'source ' => array (
1581+ 'worktree_stale_only ' => array (
1582+ 'type ' => 'boolean ' ,
1583+ 'description ' => 'Only plan stale/inactive worktrees for destructive removal. ' ,
1584+ ),
1585+ 'source ' => array (
15821586 'type ' => 'string ' ,
15831587 'description ' => 'Caller source marker. ' ,
15841588 ),
1585- 'user_id ' => array ( 'type ' => 'integer ' ),
1586- 'agent_id ' => array ( 'type ' => 'integer ' ),
1587- 'agent_slug ' => array ( 'type ' => 'string ' ),
1589+ 'user_id ' => array ( 'type ' => 'integer ' ),
1590+ 'agent_id ' => array ( 'type ' => 'integer ' ),
1591+ 'agent_slug ' => array ( 'type ' => 'string ' ),
15881592 ),
15891593 ),
15901594 'output_schema ' => array (
@@ -2327,18 +2331,20 @@ private function registerAbilities(): void {
23272331 'force_artifact_cleanup ' => array ( 'type ' => 'boolean ' ),
23282332 'worktree_older_than ' => array ( 'type ' => 'string ' ),
23292333 'worktree_sort ' => array ( 'type ' => 'string ' ),
2334+ 'worktree_stale_only ' => array ( 'type ' => 'boolean ' ),
23302335 'plan ' => array ( 'type ' => 'object ' ),
23312336 ),
23322337 ),
23332338 'output_schema ' => array (
23342339 'type ' => 'object ' ,
23352340 'properties ' => array (
2336- 'success ' => array ( 'type ' => 'boolean ' ),
2337- 'mode ' => array ( 'type ' => 'string ' ),
2338- 'plan_id ' => array ( 'type ' => 'string ' ),
2339- 'rows ' => array ( 'type ' => 'object ' ),
2340- 'chunks ' => array ( 'type ' => 'array ' ),
2341- 'summary ' => array ( 'type ' => 'object ' ),
2341+ 'success ' => array ( 'type ' => 'boolean ' ),
2342+ 'mode ' => array ( 'type ' => 'string ' ),
2343+ 'plan_id ' => array ( 'type ' => 'string ' ),
2344+ 'rows ' => array ( 'type ' => 'object ' ),
2345+ 'action_rows ' => array ( 'type ' => 'object ' ),
2346+ 'chunks ' => array ( 'type ' => 'array ' ),
2347+ 'summary ' => array ( 'type ' => 'object ' ),
23422348 ),
23432349 ),
23442350 'execute_callback ' => array ( self ::class, 'workspaceCleanupPlan ' ),
@@ -3609,7 +3615,7 @@ public static function workspaceCleanupRun( array $input ): array|\WP_Error {
36093615
36103616 $ mode = strtolower (preg_replace ('/[^a-z0-9_\-]/ ' , '' , (string ) ( $ input ['mode ' ] ?? 'retention ' )));
36113617 $ map = array (
3612- 'inventory ' => array (
3618+ 'inventory ' => array (
36133619 'task_type ' => 'workspace_hygiene_report ' ,
36143620 'params ' => array (
36153621 'include_cleanup ' => true ,
@@ -3618,7 +3624,7 @@ public static function workspaceCleanupRun( array $input ): array|\WP_Error {
36183624 'size_limit ' => 200 ,
36193625 ),
36203626 ),
3621- 'artifacts ' => array (
3627+ 'artifacts ' => array (
36223628 'task_type ' => 'workspace_retention_cleanup ' ,
36233629 'params ' => array (
36243630 'dry_run ' => false ,
@@ -3627,7 +3633,18 @@ public static function workspaceCleanupRun( array $input ): array|\WP_Error {
36273633 'skip_github ' => true ,
36283634 ),
36293635 ),
3630- 'retention ' => array (
3636+ 'stale-worktrees ' => array (
3637+ 'task_type ' => 'workspace_retention_cleanup ' ,
3638+ 'params ' => array (
3639+ 'dry_run ' => false ,
3640+ 'artifact_cleanup ' => false ,
3641+ 'worktree_cleanup ' => true ,
3642+ 'skip_github ' => true ,
3643+ 'worktree_older_than ' => '14d ' ,
3644+ 'worktree_stale_only ' => true ,
3645+ ),
3646+ ),
3647+ 'retention ' => array (
36313648 'task_type ' => 'workspace_retention_cleanup ' ,
36323649 'params ' => array (
36333650 'dry_run ' => false ,
@@ -3637,7 +3654,7 @@ public static function workspaceCleanupRun( array $input ): array|\WP_Error {
36373654 'worktree_older_than ' => '14d ' ,
36383655 ),
36393656 ),
3640- 'emergency ' => array (
3657+ 'emergency ' => array (
36413658 'task_type ' => 'workspace_disk_emergency_cleanup ' ,
36423659 'params ' => array (
36433660 'artifact_chunk_size ' => 10 ,
@@ -3663,6 +3680,21 @@ public static function workspaceCleanupRun( array $input ): array|\WP_Error {
36633680 if ( isset ($ input ['older_than ' ]) && '' !== trim ( (string ) $ input ['older_than ' ]) ) {
36643681 $ params ['worktree_older_than ' ] = trim ( (string ) $ input ['older_than ' ]);
36653682 }
3683+ if ( isset ($ input ['worktree_stale_only ' ]) ) {
3684+ $ params ['worktree_stale_only ' ] = (bool ) $ input ['worktree_stale_only ' ];
3685+ }
3686+ if ( 'artifacts ' === $ mode ) {
3687+ if ( isset ($ input ['limit ' ]) ) {
3688+ $ params ['limit ' ] = (int ) $ input ['limit ' ];
3689+ }
3690+ if ( isset ($ input ['offset ' ]) ) {
3691+ $ params ['offset ' ] = (int ) $ input ['offset ' ];
3692+ }
3693+ if ( ! empty ($ input ['exhaustive ' ]) ) {
3694+ $ params ['exhaustive ' ] = true ;
3695+ }
3696+ }
3697+
36663698 $ context = array ();
36673699 if ( isset ($ input ['user_id ' ]) ) {
36683700 $ context ['user_id ' ] = (int ) $ input ['user_id ' ];
@@ -4046,6 +4078,7 @@ public static function workspaceCleanupPlan( array $input ): array|\WP_Error {
40464078 'force_artifact_cleanup ' => ! empty ($ input ['force_artifact_cleanup ' ]),
40474079 'include_resolvers ' => ! empty ($ input ['include_resolvers ' ]),
40484080 'mode ' => (string ) ( $ input ['mode ' ] ?? 'cleanup_plan ' ),
4081+ 'worktree_stale_only ' => ! empty ($ input ['worktree_stale_only ' ]),
40494082 );
40504083 foreach ( array ( 'include_artifacts ' , 'include_worktrees ' ) as $ key ) {
40514084 if ( array_key_exists ($ key , $ input ) ) {
0 commit comments