Skip to content

refactor: extract duplicated exec, traversal and item-building logic into shared utilities - #83

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1787003086-shared-utils
Open

refactor: extract duplicated exec, traversal and item-building logic into shared utilities#83
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1787003086-shared-utils

Conversation

@devin-ai-integration

Copy link
Copy Markdown

What does this PR do?

Removes ~580 lines of duplicated logic by extracting shared utilities and rewiring every caller. No behavior or output changes.

New utilities:

  • utils/exec.tsexecCommand(command, args, timeout) (spawn-based, no shell) + findExecutable(candidates); replaces 5 near-identical copies (docker, homebrew, dns-cache, purgeable, timemachine) and 3 copies of the absolute-path binary probe. Absolute candidate paths and arg arrays are preserved, so the $PATH/injection hardening is unchanged; per-call timeouts keep their original values (10s DNS, 60s purge, 30s default).
  • utils/concurrency.tsmapPool(items, concurrency, fn); replaces the private pool in git-worktrees and the Promise.race-based runWithConcurrency in scanners/index.ts, which now just wraps it to keep swallowing+logging per-scanner failures.
  • utils/walk.tswalkFiles(root, { maxDepth, includeHidden }, onFile); replaces the recursive depth-limited traversals in large-files and duplicates (hidden-entry skipping and permission-error swallowing preserved).
  • utils/fs.tscreatePathItem(path, name, { skipEmpty }) and collectDirectoryItems(paths); replace the exists -> getSize -> stat -> push block repeated in 4 scanners and the if (await exists(dir)) items.push(...await getDirectoryItems(dir)) block repeated in 7.
  • utils/size.tssumItemSizes(items) for the reduce((sum, i) => sum + i.size, 0) repetition.
  • commands/shared.tsSAFETY_ICONS (previously defined identically in clean, scan, interactive), plus runCleanSelections/countSelectedItems/sumSelectedSize for the clean loop duplicated between clean and interactive.

MaintenanceResult moved to maintenance/types.ts (it was declared twice and imported from dns-cache by timemachine); maintenance/index.ts re-exports it from the new location.

Print/formatting code in clean vs interactive was intentionally left alone — the wording differs, so merging it would change user-visible output.

Type of change

  • Improvement to existing feature

Related issue

N/A

Checklist

  • bun run lint passes
  • bun run test passes (no regressions)
  • bun run build succeeds
  • New tests added for new behavior (utils/walk.test.ts, utils/concurrency.test.ts; 354 tests pass)
  • I've tested this on macOS locally — not possible from a Linux dev box; covered by the existing suite

Notes for reviewer

Worth a look at runWithConcurrency in scanners/index.ts: the old version raced promises as it queued them, the new one is a fixed worker pool over mapPool. Same limit and same error handling, but scheduling order differs slightly.

Link to Devin session: https://app.devin.ai/sessions/f560eeb632a4468a93f3ce06d0b53cc5
Requested by: @guhcostan

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@guhcostan guhcostan self-assigned this Aug 17, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant