|
19 | 19 | use DataMachineCode\Workspace\RemoteWorkspaceBackend; |
20 | 20 | use DataMachineCode\Workspace\RunnerWorkspacePublisher; |
21 | 21 | use DataMachineCode\Workspace\Workspace; |
| 22 | +use DataMachineCode\Workspace\WorkspaceAbandonedCleanupOrchestrator; |
22 | 23 | use DataMachineCode\Workspace\WorkspaceReader; |
23 | 24 | use DataMachineCode\Workspace\WorkspaceWriter; |
24 | 25 | use DataMachineCode\Support\GitRunner; |
@@ -2183,6 +2184,69 @@ private function registerAbilities(): void { |
2183 | 2184 | ) |
2184 | 2185 | ); |
2185 | 2186 |
|
| 2187 | + AbilityRegistry::register( |
| 2188 | + 'datamachine-code/workspace-worktree-abandoned-cleanup', |
| 2189 | + array( |
| 2190 | + 'label' => 'Orchestrate Abandoned Worktree Cleanup', |
| 2191 | + 'description' => 'Run the bounded abandoned-worktree cleanup orchestration: reconcile metadata, promote safe cleanup candidates, remove eligible rows, prune git metadata, and return continuation evidence.', |
| 2192 | + 'category' => 'datamachine-code-workspace', |
| 2193 | + 'input_schema' => array( |
| 2194 | + 'type' => 'object', |
| 2195 | + 'properties' => array( |
| 2196 | + 'apply' => array( |
| 2197 | + 'type' => 'boolean', |
| 2198 | + 'description' => 'If true, write cleanup metadata and remove bounded cleanup-eligible worktrees. Defaults to preview mode.', |
| 2199 | + ), |
| 2200 | + 'force' => array( |
| 2201 | + 'type' => 'boolean', |
| 2202 | + 'description' => 'Forward force to bounded cleanup removal. Unpushed commits remain protected.', |
| 2203 | + ), |
| 2204 | + 'limit' => array( |
| 2205 | + 'type' => 'integer', |
| 2206 | + 'description' => 'Page/removal limit, clamped to 1..1000. Defaults to 100.', |
| 2207 | + ), |
| 2208 | + 'passes' => array( |
| 2209 | + 'type' => 'integer', |
| 2210 | + 'description' => 'Maximum apply passes, clamped to 1..25. Preview mode runs one pass.', |
| 2211 | + ), |
| 2212 | + 'offset' => array( |
| 2213 | + 'type' => 'integer', |
| 2214 | + 'description' => 'Stage pagination offset for resumed runs.', |
| 2215 | + ), |
| 2216 | + 'stage' => array( |
| 2217 | + 'type' => 'string', |
| 2218 | + 'enum' => array( 'reconcile', 'finalized', 'equivalent-clean', 'merged', 'remote-clean', 'bounded' ), |
| 2219 | + 'description' => 'Stage to start from. Defaults to reconcile.', |
| 2220 | + ), |
| 2221 | + 'until_budget' => array( |
| 2222 | + 'type' => 'string', |
| 2223 | + 'description' => 'Optional compact wall-clock budget such as 60s, 10m, or 1h.', |
| 2224 | + ), |
| 2225 | + 'source' => array( |
| 2226 | + 'type' => 'string', |
| 2227 | + 'description' => 'Caller source marker forwarded to underlying cleanup abilities.', |
| 2228 | + ), |
| 2229 | + ), |
| 2230 | + ), |
| 2231 | + 'output_schema' => array( |
| 2232 | + 'type' => 'object', |
| 2233 | + 'properties' => array( |
| 2234 | + 'success' => array( 'type' => 'boolean' ), |
| 2235 | + 'mode' => array( 'type' => 'string' ), |
| 2236 | + 'applied' => array( 'type' => 'boolean' ), |
| 2237 | + 'summary' => array( 'type' => 'object' ), |
| 2238 | + 'steps' => array( 'type' => 'object' ), |
| 2239 | + 'blocked' => array( 'type' => 'array' ), |
| 2240 | + 'continuation' => array( 'type' => 'object' ), |
| 2241 | + 'next_commands' => array( 'type' => 'array' ), |
| 2242 | + ), |
| 2243 | + ), |
| 2244 | + 'execute_callback' => array( self::class, 'worktreeAbandonedCleanup' ), |
| 2245 | + 'permission_callback' => fn() => PermissionHelper::can_manage(), |
| 2246 | + 'meta' => array( 'show_in_rest' => false ), |
| 2247 | + ) |
| 2248 | + ); |
| 2249 | + |
2186 | 2250 | AbilityRegistry::register( |
2187 | 2251 | 'datamachine-code/workspace-worktree-cleanup-artifacts', |
2188 | 2252 | array( |
@@ -4140,6 +4204,18 @@ public static function worktreeActiveNoSignalRemoteCleanApply( array $input ): a |
4140 | 4204 | return $workspace->worktree_active_no_signal_remote_clean_apply($opts); |
4141 | 4205 | } |
4142 | 4206 |
|
| 4207 | + /** |
| 4208 | + * Orchestrate abandoned-worktree cleanup across existing bounded abilities. |
| 4209 | + * |
| 4210 | + * @param array $input Orchestration input. |
| 4211 | + * @return array<string,mixed>|\WP_Error |
| 4212 | + */ |
| 4213 | + public static function worktreeAbandonedCleanup( array $input ): array|\WP_Error { |
| 4214 | + $orchestrator = new WorkspaceAbandonedCleanupOrchestrator(); |
| 4215 | + |
| 4216 | + return $orchestrator->run($input); |
| 4217 | + } |
| 4218 | + |
4143 | 4219 | /** |
4144 | 4220 | * Remove profile-derived artifacts inside workspace worktrees. |
4145 | 4221 | * |
|
0 commit comments