/** * SDK primitive for the `cleo worktree prune --orphaned` command (T9547). * * Exposes {@link pruneOrphanedWorktreesByStatus} — picks up the T9546 * structured listing, filters to orphan/merged worktrees, and removes each * one via the NAPI destroyWorktree binding (T11123). Every action is * recorded in `.cleo/audit/worktree-lifecycle.jsonl` via * {@link appendWorktreeAuditEntry}. * * Naming note: there is already a {@link pruneOrphanedWorktrees} export in * `packages/core/src/spawn/branch-lock.ts` (T1118 — preserve-set-based cleanup * used by spawn). The T9547 primitive intentionally uses the suffix * `ByStatus` so both functions can coexist; the lifecycle command surface * targets the status-classified listing, the spawn surface targets the * known-active task IDs. * * Interactive Y/N prompting is the CLI's responsibility — the SDK primitive * is non-interactive. Callers pass `opts.paths` to limit the prune to a * pre-confirmed subset; omit the field to prune every orphan/merged entry. * * @task T9547 * @epic T9515 */ import { type EngineResult, type PruneOrphanedWorktreesOpts, type PruneOrphanedWorktreesResult, type WorktreeInfo } from '@cleocode/contracts'; /** * Drive the orphan / merged worktree prune flow used by * `cleo worktree prune --orphaned`. * * Steps: * 1. Re-use {@link listWorktrees} to enumerate every worktree with full * status classification (T9546). No raw porcelain re-parsing here. * 2. Filter to entries whose `statusCategory` is `orphan` or `merged`. The * lifecycle command intentionally excludes `stale` and `locked` — those * are handled by future T9515 follow-ups (T9548 auto-invoke, force-unlock). * 3. When the caller passes `opts.paths`, intersect the candidate set with * it so the CLI can render per-orphan Y/N prompts and then call this * primitive with the user-confirmed subset. * 4. For each candidate, invoke the NAPI destroyWorktree binding (T11123) for * atomic unlock+force-remove via Rust worktrunk-core. On failure, falls * back to gitSilent worktree prune for administrative cleanup. * 5. When the prune succeeded AND the branch is reachable from `main` (the * T9546 `isMerged` flag), also drop the local `task/` branch via * `git branch -D `. We never delete unmerged branches here — * callers must use `cleo orchestrate worktree-complete` first. * 6. Append one {@link WorktreeLifecycleAuditEntry} per attempted prune. * Under `--dry-run`, no audit entry is written and no filesystem action * is taken — callers see what WOULD happen via the returned `outcomes`. * * @param opts - See {@link PruneOrphanedWorktreesOpts}. * @returns EngineResult wrapping a {@link PruneOrphanedWorktreesResult}. */ export declare function pruneOrphanedWorktreesByStatus(opts: PruneOrphanedWorktreesOpts): Promise>; /** * Map a {@link WorktreeInfo} entry's `statusCategory` to a short human-readable * reason string used in audit logs + envelope outcomes. */ export declare function reasonForStatus(wt: WorktreeInfo): string; /** * Remove a single worktree from disk + clean up its branch when safe. * * T11123: Uses the NAPI destroyWorktree binding (Rust worktrunk-core) for * atomic unlock+force-remove, retiring the raw git worktree remove/unlock * shell-outs. The NAPI binding handles both unlock and directory removal * atomically. * * Steps: * 1. Invoke `napiDestroyWorktree({ repoRoot, worktreePath, force: true })` * — atomic unlock + force-remove via Rust worktrunk-core. * 2. Fallback to gitSilent worktree prune if NAPI fails (administrative * cleanup for stale entries). * 3. When the worktree was `isMerged`, delete the local `task/` branch * with `git branch -D ` — safe because the branch tip is * already reachable from `main`. * * Never throws — failures are reported in the returned object. */ export declare function removeWorktreeFromDisk(wt: WorktreeInfo, projectRoot: string): { success: true; branchDeleted: boolean; } | { success: false; error: string; }; //# sourceMappingURL=prune.d.ts.map