Skip to content

chore(scripts): add cross-platform clean:build and clean:build:full - #768

Merged
rinchen merged 3 commits into
mainfrom
feat/cross-platform-clean-build
Aug 2, 2026
Merged

rinchen merged 3 commits into
mainfrom
feat/cross-platform-clean-build

Conversation

@rinchen

@rinchen rinchen commented Aug 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds a cross-platform build-artifact cleanup helper (scripts/clean-build.mjs) for linux / darwin / win32, wired as two pnpm commands, replacing the ad-hoc habit of manually rm -rf-ing build output.

  • pnpm run clean:build — shallow: removes build dists, test output, and caches (dist, dist-electron, release, coverage, .vitest-reports, test-results, playwright-report, .eslintcache) while keeping node_modules/ and the Reticulum sidecar, so pnpm run dev / pnpm start and Reticulum remain functional.
  • pnpm run clean:build:full — full: additionally removes node_modules, reticulum-sidecar/target/ (~22G), and the bundled sidecar binary, then restores a working environment via pnpm install + pnpm run reticulum:sidecar:build.

Safety features

  • Always prompts Proceed? [y/N] (default N) before deleting; -y / --yes skips the prompt but still echoes the plan.
  • Non-interactive stdin (CI) without -y aborts instead of hanging.
  • Strict allowlist of paths, resolved under the repo root and asserted to stay inside it.
  • Reinstall is skipped when full-clean found nothing to remove.

Testing (verified manually)

  • pnpm run clean:build -- -y removed only the 8 tier-1 artifacts and preserved node_modules/ + reticulum-sidecar/target/.
  • pnpm run clean:build:full -- -y removed node_modules/ + target/, then pnpm install (native modules rebuilt for Electron 41.10.3) and a fresh sidecar build (40.3s) restored the working env. Dev resolves the sidecar from reticulum-sidecar/target/debug (reticulum-sidecar-path.ts), so Reticulum works.
  • Vitest scripts/clean-build.test.mjs: 10/10 PASS; ESLint no issues; Prettier + markdownlint clean.

Files

  • scripts/clean-build.mjs, scripts/clean-build.test.mjs (new)
  • package.json (adds clean:build, clean:build:full)
  • docs/development-environment.md (Maintenance block, Setup/helpers table, explainer prose)

Summary by CodeRabbit

  • New Features

    • Added cross-platform commands for cleaning build artifacts.
    • Added shallow and full cleanup options, with confirmation prompts and a --yes option for automation.
    • Full cleanup can reinstall dependencies and rebuild required components when needed.
  • Documentation

    • Documented cleanup commands, safeguards, behavior, and usage scenarios.
  • Tests

    • Added coverage for cleanup modes, safety checks, confirmations, and reinstall behavior.

@coderabbitai

coderabbitai Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@rinchen, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 31 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: QUIET

Plan: Pro Plus

Run ID: 6a65e8c7-b8a3-4253-8c21-b9b309c74e50

📥 Commits

Reviewing files that changed from the base of the PR and between 7d4855d and f6cf6ab.

📒 Files selected for processing (2)
  • scripts/clean-build.mjs
  • scripts/clean-build.test.mjs
📝 Walkthrough

Walkthrough

Added cross-platform clean:build and clean:build:full commands. The CLI removes allowlisted build artifacts, protects repository boundaries, requires confirmation when appropriate, and can reinstall dependencies and rebuild the Reticulum sidecar.

Changes

Build cleanup workflow

Layer / File(s) Summary
Cleanup planning and safety
scripts/clean-build.mjs
The CLI resolves repository-bound paths, applies shallow or full cleanup tiers, plans restoration commands, parses flags, and handles confirmation safeguards.
Cleanup execution and validation
scripts/clean-build.mjs, scripts/clean-build.test.mjs, package.json
The CLI removes existing targets, optionally reinstalls dependencies and rebuilds the sidecar, and exposes package scripts. Tests cover parsing, safety, aborts, cleanup, and restoration behavior.
Command documentation
docs/development-environment.md
The documentation describes both commands, confirmation behavior, cleanup scopes, safeguards, and restoration actions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Developer
  participant clean-build.mjs
  participant Filesystem
  participant RestorationCommands
  Developer->>clean-build.mjs: Run cleanup command
  clean-build.mjs->>Filesystem: Resolve and detect cleanup targets
  clean-build.mjs->>Developer: Show plan and request confirmation
  Developer->>clean-build.mjs: Confirm or use --yes
  clean-build.mjs->>Filesystem: Remove selected targets
  clean-build.mjs->>RestorationCommands: Reinstall dependencies and rebuild sidecar
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the added cross-platform clean:build and clean:build:full scripts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/cross-platform-clean-build

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Note

Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.

🟡 Other comments (2)
scripts/clean-build.mjs-88-100 (1)

88-100: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Route the plan through the supplied stdout.

runClean accepts io.stdout, but printPlan writes to the global console. Callers cannot capture the plan through the injected stream, and the tests still emit plan output despite passing silent.

Pass stdout to printPlan and use stdout.write. As per path instructions, use console.debug/warn/error rather than bare console.log.

Also applies to: 163-163

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/clean-build.mjs` around lines 88 - 100, Update printPlan to accept
the supplied stdout stream and write all plan messages through stdout.write
instead of the global console, then pass runClean’s io.stdout when invoking
printPlan. Preserve the existing plan content and use console.debug/warn/error
only where console output remains necessary, avoiding bare console.log.

Source: Path instructions

scripts/clean-build.mjs-83-84 (1)

83-84: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Check allowlisted paths without following broken symlinks.

existsSync resolves symlink targets, so a dangling allowlisted link is skipped by the cleanup even though the script should remove symlinks as links. Use an lstatSync helper at scripts/clean-build.mjs 83, 141, and 172 that returns false only for ENOENT.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/clean-build.mjs` around lines 83 - 84, Replace existsSync checks in
the tier2Present logic and the corresponding checks around cleanup paths with an
lstatSync-based helper that treats existing symlinks, including dangling links,
as present and returns false only for ENOENT. Reuse this helper at the locations
associated with tier2Present and the cleanup checks rather than following
symlink targets.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/clean-build.mjs`:
- Around line 55-70: Update resolvePaths to inspect each existing path component
between rootDir and entry.abs with lstatSync, rejecting any symbolic-link
ancestor before returning resolved entries for deletion; retain the existing
lexical repository-boundary check. Add a regression test covering a symlinked
reticulum-sidecar directory that points outside rootDir and verifies resolution
is rejected.
- Around line 178-192: The restoration branch in runClean must signal failure
when either pnpm install or the sidecar rebuild fails. After logging the
failure, throw or otherwise return a failure that makes the direct CLI exit
nonzero, while preserving the removed state for rollback; add tests covering
each failed restoration command.
- Around line 133-137: Update runCmd to resolve pnpm to a Windows-compatible
executable before calling spawnSync with shell: false, or route Windows commands
through cmd.exe /c while preserving existing behavior on other platforms. Ensure
restore commands remain runnable after node_modules removal, and add a Windows
smoke test covering pnpm invocation.

---

Other comments:
In `@scripts/clean-build.mjs`:
- Around line 88-100: Update printPlan to accept the supplied stdout stream and
write all plan messages through stdout.write instead of the global console, then
pass runClean’s io.stdout when invoking printPlan. Preserve the existing plan
content and use console.debug/warn/error only where console output remains
necessary, avoiding bare console.log.
- Around line 83-84: Replace existsSync checks in the tier2Present logic and the
corresponding checks around cleanup paths with an lstatSync-based helper that
treats existing symlinks, including dangling links, as present and returns false
only for ENOENT. Reuse this helper at the locations associated with tier2Present
and the cleanup checks rather than following symlink targets.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: QUIET

Plan: Pro Plus

Run ID: 4b38ff69-a712-4e55-a992-91ec16239b34

📥 Commits

Reviewing files that changed from the base of the PR and between 81e4e57 and 7d4855d.

📒 Files selected for processing (4)
  • docs/development-environment.md
  • package.json
  • scripts/clean-build.mjs
  • scripts/clean-build.test.mjs

Comment thread scripts/clean-build.mjs Resolved
Comment thread scripts/clean-build.mjs Resolved
Comment thread scripts/clean-build.mjs Outdated
Comment on lines +178 to +192
if (reinstall.install && removed.length > 0) {
stdout.write('Restoring working environment…\n');
const installOk = run(['pnpm', 'install'], rootDir) === 0;
let sidecarOk = true;
if (installOk && reinstall.sidecar) {
sidecarOk = run(['pnpm', 'run', 'reticulum:sidecar:build'], rootDir) === 0;
}
if (!installOk) {
stderr.write('clean-build: `pnpm install` failed — dependencies not restored.\n');
} else if (!sidecarOk) {
stderr.write(
'clean-build: sidecar rebuild failed (is cargo installed?) — Reticulum may be unavailable.\n',
);
}
return { removed, reinstalled: installOk && sidecarOk };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Return a failure status when restoration fails.

When pnpm install or the sidecar build fails, runClean returns normally. The direct CLI path exits with status 0 even though node_modules was removed and the environment was not restored.

Throw after logging the restoration failure. Preserve the removed state for rollback, or document and implement an explicit recovery path. Add failure-path tests.

As per path instructions, preserve state on command failure.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/clean-build.mjs` around lines 178 - 192, The restoration branch in
runClean must signal failure when either pnpm install or the sidecar rebuild
fails. After logging the failure, throw or otherwise return a failure that makes
the direct CLI exit nonzero, while preserving the removed state for rollback;
add tests covering each failed restoration command.

Source: Path instructions

@rinchen
rinchen merged commit d93f72c into main Aug 2, 2026
11 checks passed
@rinchen
rinchen deleted the feat/cross-platform-clean-build branch August 2, 2026 17:04
@rinchen rinchen added the chore Internal app functionality updates; non-user-facing changes and repo maintenance label Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Internal app functionality updates; non-user-facing changes and repo maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant