Skip to content

Make cleanup-eligible worktree review/apply flow symmetric #271

@chubes4

Description

@chubes4

Problem

The current worktree cleanup UX exposes a safe-looking review surface for explicit cleanup_eligible worktrees, but does not provide an obvious symmetric apply path for exactly that reviewed set.

Observed flow:

  1. workspace worktree add warned that the workspace had hundreds of worktree-like directories and suggested cleanup dry-runs.
  2. Ran:
    studio wp datamachine-code workspace worktree cleanup --dry-run --inventory-only --skip-github --format=json
  3. The preview reported:
    • would_remove: 38
    • cleanup_buckets.explicit_cleanup_candidates: 38
    • candidates_by_signal.cleanup_eligible: 38
  4. User approved cleaning those 38 explicit cleanup-eligible worktrees.
  5. Tried to apply the same bounded inventory cleanup without --dry-run:
    studio wp datamachine-code workspace worktree cleanup --inventory-only --skip-github --format=json
  6. DMC refused with:
    Inventory-only cleanup is review-only. Pass --dry-run, then run full cleanup to apply a reviewed plan.
    

That refusal is reasonable for safety, but it leaves the operator without a clear way to apply exactly the reviewed cleanup_eligible set.

Why this matters

The recommended next step, "run full cleanup," can expand the decision surface from:

  • the 38 explicit lifecycle cleanup candidates just reviewed

into:

  • a broader merge/PR signal scan with different candidate discovery behavior.

That makes the safe review surface and safe apply surface asymmetric.

Desired behavior

DMC should offer a clear bounded apply path for the exact category that was reviewed.

Possible shapes:

studio wp datamachine-code workspace worktree bounded-cleanup-eligible-apply --dry-run --limit=50
studio wp datamachine-code workspace worktree bounded-cleanup-eligible-apply --limit=50

or a run-id based workflow:

studio wp datamachine-code workspace cleanup plan --mode=cleanup-eligible --format=json
studio wp datamachine-code workspace cleanup apply <run-id>

Acceptance criteria

  • A dry-run that reports explicit cleanup_eligible worktrees prints the exact safe apply command for that same reviewed class.
  • The apply path only removes lifecycle cleanup_eligible rows unless the operator explicitly asks for broader full cleanup.
  • Apply revalidates dirty worktree, unpushed commits, containment, and primary-safety before deletion.
  • Apply does not discover unrelated full-cleanup candidates as part of applying the reviewed bounded set.
  • Artifact cleanup remains separate and does not remove dependencies from active worktrees by default.
  • Error messages avoid "run full cleanup" when the operator is trying to apply a bounded cleanup-eligible preview.

Related operator note

Artifact cleanup dry-run also reported reconstructable artifacts in active worktrees, including active minion worktrees. That behavior may be technically correct, but should remain opt-in/separate from worktree deletion so cleanup during active parallel work does not disrupt running sessions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions