Skip to content

Commit 06720d4

Browse files
Refactor abandoned worktree cleanup orchestration (#764)
* refactor: extract abandoned cleanup orchestration * fix: satisfy worktree cleanup lint * fix: clear remaining cleanup lint findings * fix: add phpstan stub for datamachine cli base --------- Co-authored-by: homeboy-ci[bot] <266378653+homeboy-ci[bot]@users.noreply.github.com>
1 parent 783e435 commit 06720d4

6 files changed

Lines changed: 759 additions & 543 deletions

File tree

inc/Abilities/WorkspaceAbilities.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use DataMachineCode\Workspace\RemoteWorkspaceBackend;
2020
use DataMachineCode\Workspace\RunnerWorkspacePublisher;
2121
use DataMachineCode\Workspace\Workspace;
22+
use DataMachineCode\Workspace\WorkspaceAbandonedCleanupOrchestrator;
2223
use DataMachineCode\Workspace\WorkspaceReader;
2324
use DataMachineCode\Workspace\WorkspaceWriter;
2425
use DataMachineCode\Support\GitRunner;
@@ -2183,6 +2184,69 @@ private function registerAbilities(): void {
21832184
)
21842185
);
21852186

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+
21862250
AbilityRegistry::register(
21872251
'datamachine-code/workspace-worktree-cleanup-artifacts',
21882252
array(
@@ -4140,6 +4204,18 @@ public static function worktreeActiveNoSignalRemoteCleanApply( array $input ): a
41404204
return $workspace->worktree_active_no_signal_remote_clean_apply($opts);
41414205
}
41424206

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+
41434219
/**
41444220
* Remove profile-derived artifacts inside workspace worktrees.
41454221
*

0 commit comments

Comments
 (0)