Repository navigation
feat: Add shared lib/common helper library for modules and runner - #2
Conversation
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughIntroduces a shared Bash utility library ( Changes
Sequence Diagram(s)sequenceDiagram
participant Runner as ./run
participant ModuleDiscovery as Module Discovery
participant Filter as Filter Logic
participant OSDetect as OS Detection<br/>(lib/common)
participant Module as Module Script
participant Summary as Summary Report
Runner->>ModuleDiscovery: Discover executables in runs/
ModuleDiscovery-->>Runner: [00-system-update, 10-core-cli, ...]
Runner->>Filter: Apply --only/--skip<br/>matches_filter() & should_run()
Filter-->>Runner: Filtered module list
Runner->>Module: Run subshell for each module
Module->>OSDetect: detect_os() on source
OSDetect-->>Module: SETUP_OS exported
Module->>Module: Execute setup steps<br/>(require_os, pkg_install, etc.)
Module-->>Runner: exit code + stdout/stderr
Runner->>Summary: Record success/failure/<br/>skip per module
Summary-->>Runner: Consolidated status
Runner->>Runner: Log summary table<br/>Exit 0 or 1
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Review rate limit: 0/1 reviews remaining, refill in 51 minutes and 15 seconds.Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/common`:
- Around line 191-197: The ensure_symlink function currently calls run_cmd for
mv, mkdir, and ln but ignores their outcomes and always calls log_success;
change it so failures are detected and handled: have run_cmd propagate errors
(throw or return non-zero) or capture its exit status for each invocation (mv,
mkdir -p, ln -sf) and if any command fails, log an error (use log_error or
similar) and return/exit without calling log_success; only call log_success
"symlink created: $link -> $source" when all run_cmd calls succeed. Ensure
references: ensure_symlink, run_cmd, mv, mkdir, ln, and log_success.
- Line 181: The symlink comparison uses "readlink -f" which is not portable on
macOS; replace it with a portable resolver: add a helper (e.g.,
canonicalize_path or resolve_path) that first prefers "greadlink -f" if
available, falls back to "readlink -f" if present, and otherwise uses a
POSIX-safe alternative (eg. realpath if present or a small python/perl command)
to produce canonical paths; then change the comparison line that references
"$link" and "$source" to call that helper for both sides (instead of "$(readlink
-f "$link")" and "$(readlink -f "$source")") to ensure macOS compatibility.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
…tion functionality
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/common`:
- Around line 203-233: The ensure_symlink function can back up the source when
source and link reference the same path; update ensure_symlink to canonicalize
and compare source and link (using resolve_path or an equivalent realpath)
before the backup branch and, if they resolve to the same filesystem path (or
"$source" == "$link"), treat the symlink as already correct: log_info and return
0 instead of moving/backup. Modify the existing resolved_link/resolved_source
logic in ensure_symlink (and/or add a pre-backup check) so the backup block is
skipped when resolved_source == resolved_link or the raw arguments are
identical, preventing destructive behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
… and existing link checks in `ensure_symlink` function
|
@coderabbitai rate limit |
|
Review rate limit: 0/1 reviews remaining, refill in 52 minutes and 30 seconds. |
…tooling scripts, and Docker smoke tests
There was a problem hiding this comment.
Actionable comments posted: 6
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
runs/00-system-update (1)
46-55:⚠️ Potential issue | 🟡 MinorVerification failure doesn't cause module to exit non-zero.
If a package fails to install and
log_erroris triggered, the module still exits successfully. Consider tracking errors and exiting non-zero if any required packages are missing.🛡️ Proposed fix
# ── Verify ── log_info "Verifying base packages..." +verify_failed=0 for cmd in bash curl git unzip zip; do if has_cmd "$cmd"; then log_success "$cmd: $(command -v "$cmd")" else log_error "$cmd not found after install" + verify_failed=1 fi done + +if [[ $verify_failed -ne 0 ]]; then + exit 1 +fi🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@runs/00-system-update` around lines 46 - 55, The verification loop using log_info/log_success/log_error and has_cmd currently does not cause a non-zero exit when packages are missing; modify the loop to track failures (e.g., a missing_count or missing_packages list) and increment/append inside the else branch where log_error is called, then after the for loop check that tracker and if any failures exist call log_error summarizing the missing packages and exit 1 so the module fails fast; update the functions/variables referenced (has_cmd, log_error, log_success) accordingly.
🧹 Nitpick comments (6)
runs/99-manual (1)
14-38: Use a heredoc for the checklist to reduce repetition.Lines 17–38 are many repetitive
echocalls; a single heredoc will be simpler to maintain.♻️ Proposed cleanup
log_info "The following items require manual action:" -echo "" - -echo " 1. JetBrains Toolbox" -echo " → https://www.jetbrains.com/toolbox-app/" -echo "" - -echo " 2. Import SSH key into Git provider (GitHub/GitLab)" -echo " → cat ~/.ssh/id_ed25519.pub" -echo "" - -echo " 3. Import KeePassXC database" -echo " → Open KeePassXC and point to your database file" -echo "" - -echo " 4. Log into Firefox / sync browser profile" -echo "" - -echo " 5. Configure dotfiles symlinks" -echo " → Review and update runs/80-dotfiles" -echo "" - -echo " 6. Set up Obsidian vault" -echo " → Point Obsidian to your vault location" -echo "" +cat <<'EOF' + + 1. JetBrains Toolbox + → https://www.jetbrains.com/toolbox-app/ + + 2. Import SSH key into Git provider (GitHub/GitLab) + → cat ~/.ssh/id_ed25519.pub + + 3. Import KeePassXC database + → Open KeePassXC and point to your database file + + 4. Log into Firefox / sync browser profile + + 5. Configure dotfiles symlinks + → Review and update runs/80-dotfiles + + 6. Set up Obsidian vault + → Point Obsidian to your vault location + +EOF🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@runs/99-manual` around lines 14 - 38, Replace the repeated echo lines with a single heredoc block after the existing log_info call: keep the "log_info \"The following items require manual action:\"" call, then open a heredoc and place the entire checklist (all numbered items, arrows like "→", blank lines and the reference to "runs/80-dotfiles") inside it, then close the heredoc; this removes the multiple echo calls and preserves the exact output/formatting while making the checklist easier to maintain.scripts/dev-setup (1)
32-41: Collapse identical OS branches.Line 33–Line 41 all do the same call. You can keep OS validation but simplify maintenance by using one install path for supported OSes.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@scripts/dev-setup` around lines 32 - 41, The case branches for SETUP_OS are redundant — collapse the identical arch, ubuntu, debian, and macos branches into a single pattern branch that calls pkg_install "${MISSING[@]}" (e.g., arch|ubuntu|debian|macos) ) pkg_install "${MISSING[@]}" ;; — keep any existing OS validation/unsupported fallback in the case statement/else branch so unsupported SETUP_OS values still produce an error.runs/10-core-cli (1)
17-19: Arch and macOS install blocks can be merged.Line 17–Line 19 and Line 42–Line 44 are identical; consolidating them will reduce drift risk.
Also applies to: 42-44
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@runs/10-core-cli` around lines 17 - 19, The two identical install blocks duplicate the same pkg_install call; update the conditional(s) that check SETUP_OS so both "arch" and "macos" fall through to a single pkg_install invocation instead of duplicated blocks — e.g., consolidate the separate if [[ "$SETUP_OS" == "arch" ]]; then ... fi and the macOS block into one conditional that tests SETUP_OS for "arch" OR "macos" and calls pkg_install wget tree cloc htop vim fastfetch bat fzf eza once; keep the SETUP_OS variable and pkg_install symbol names unchanged so other logic still references them correctly.runs/80-dotfiles (1)
39-46: TODO left in symlink management path.Line 45 indicates the main behavior of this module is still pending.
If you want, I can draft a first-pass mapping scaffold using
ensure_symlinkfor common files (.zshrc, git config, starship, etc.) and you can adjust per host.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@runs/80-dotfiles` around lines 39 - 46, The symlink management file still contains a TODO log_info instead of actual mappings; replace the log_info "TODO..." line with concrete ensure_symlink calls for your common dotfiles using the existing helper (e.g., call ensure_symlink "$DOTFILES_DIR/.zshrc" "$HOME/.zshrc", ensure_symlink "$DOTFILES_DIR/.gitconfig" "$HOME/.gitconfig", ensure_symlink "$DOTFILES_DIR/.config/starship.toml" "${XDG_CONFIG_HOME:-$HOME/.config}/starship.toml", plus mappings for editors/terminals like "$DOTFILES_DIR/.config/nvim" and "$DOTFILES_DIR/.config/kitty" as needed), ensuring you reference DOTFILES_DIR and XDG_CONFIG_HOME exactly and remove the placeholder log_info line so the script actually creates the symlinks.runs/30-git-ssh (1)
67-68: Startssh-agentonly when needed.Line 67 starts a new agent each run. Prefer checking
SSH_AUTH_SOCKfirst to avoid spawning extra agents.♻️ Suggested improvement
if [[ -f "$SSH_KEY_PATH" ]]; then log_info "Ensuring SSH key is added to agent..." - eval "$(ssh-agent -s)" &>/dev/null || true + if [[ -z "${SSH_AUTH_SOCK:-}" ]]; then + eval "$(ssh-agent -s)" &>/dev/null || log_warn "Could not start ssh-agent" + fi run_cmd ssh-add "$SSH_KEY_PATH" 2>/dev/null || log_warn "Could not add key to agent" fi🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@runs/30-git-ssh` around lines 67 - 68, The script always starts a new ssh-agent via eval "$(ssh-agent -s)" which spawns agents unnecessarily; modify the logic around ssh-agent and ssh-add (the run_cmd and log_warn calls) to first check SSH_AUTH_SOCK and only start a new agent when SSH_AUTH_SOCK is empty or points to a dead socket, then proceed to run_cmd ssh-add "$SSH_KEY_PATH" and fallback to log_warn on failure—ensure the check is performed before invoking ssh-agent so you won't spawn extra agents on subsequent runs.runs/20-shell (1)
54-67: Consider using shallow clones for plugins.The plugin clones could use
--depth 1for faster initial setup since version history isn't needed for these plugins.♻️ Proposed optimization
if [[ ! -d "$ZSH_CUSTOM/plugins/zsh-autosuggestions" ]]; then log_info "Installing zsh-autosuggestions plugin..." - run_cmd git clone https://github.com/zsh-users/zsh-autosuggestions "$ZSH_CUSTOM/plugins/zsh-autosuggestions" + run_cmd git clone --depth 1 https://github.com/zsh-users/zsh-autosuggestions "$ZSH_CUSTOM/plugins/zsh-autosuggestions" else log_info "zsh-autosuggestions already installed" fi # ── zsh-syntax-highlighting (oh-my-zsh plugin) ── if [[ ! -d "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting" ]]; then log_info "Installing zsh-syntax-highlighting plugin..." - run_cmd git clone https://github.com/zsh-users/zsh-syntax-highlighting "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting" + run_cmd git clone --depth 1 https://github.com/zsh-users/zsh-syntax-highlighting "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting" else log_info "zsh-syntax-highlighting already installed" fi🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@runs/20-shell` around lines 54 - 67, Update the git clone calls that install the zsh plugins to perform shallow clones by adding the --depth 1 option; specifically modify the two git clone invocations that install "zsh-autosuggestions" and "zsh-syntax-highlighting" (invoked via run_cmd) so they include --depth 1 to speed up setup and reduce bandwidth.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@runs/30-git-ssh`:
- Line 82: The log lines currently emit full Git identity values via commands
like log_info "git user.name already set: $(git config --global user.name)" and
the similar user.email call; update these to avoid printing PII by either
removing the command substitution and logging a generic confirmation (e.g., "git
user.name is set" / "git user.email is set") or by logging a masked/placeholder
value instead, and apply the same change to both the user.name and user.email
occurrences referenced by the log_info calls to ensure no raw identities are
written to CI logs.
In `@runs/40-firewall`:
- Around line 22-33: The script sets UFW defaults and enables the firewall
without ensuring SSH is allowed, risking lockout; before calling run_cmd sudo
ufw --force enable (and after setting defaults with run_cmd sudo ufw default
deny incoming / run_cmd sudo ufw default allow outgoing) ensure you add a rule
to permit SSH (e.g., run_cmd sudo ufw allow OpenSSH or allow 22/tcp) and verify
the rule exists in ufw_status before enabling; update the block that computes
ufw_status and the enable branch (references: run_cmd, log_info, ufw_status, the
enable command) to add the allow-SSH rule if missing and only then call run_cmd
sudo ufw --force enable.
- Line 37: The command invocation that enables UFW is currently masked by
"2>/dev/null || true", hiding failures; update the invocation used by run_cmd so
it does not swallow errors: remove the "2>/dev/null || true" suppression, let
stderr surface (or capture it) and check the exit status returned by run_cmd (or
the caller) and on failure emit a clear error message and exit non‑zero so boot
enabling issues are visible; ensure the unique invocation "sudo systemctl enable
ufw --now" is the one validated and logged by run_cmd.
In `@runs/80-dotfiles`:
- Around line 31-37: The script assumes any .git at DOTFILES_DIR is the right
repo; update the existing-branch branch to validate remote by running git -C
"$DOTFILES_DIR" remote get-url origin (or equivalent) and comparing the result
to DOTFILES_REPO before calling run_cmd git -C "$DOTFILES_DIR" pull --ff-only;
if the URLs match, proceed to pull, otherwise log an error via
log_info/log_error and either abort or remove/reclone the directory using
run_cmd git clone "$DOTFILES_REPO" "$DOTFILES_DIR" to avoid updating the wrong
repository.
In `@runs/90-dev-quality`:
- Around line 23-27: The Debian/Ubuntu block currently calls pkg_install for
only shellcheck and merely warns if shfmt is missing; change it to attempt
installing shfmt as well (call pkg_install "shfmt" alongside "shellcheck" or as
a separate install) and keep the existing has_cmd(shfmt) check to fall back to
log_warn only if installation fails; update references in this block
(pkg_install, has_cmd, log_warn, shfmt, shellcheck) so the script actually
installs shfmt on supported systems rather than just warning.
In `@scripts/dev-setup`:
- Line 32: The script uses SETUP_OS under set -u before it's initialized; ensure
SETUP_OS is computed or defaulted before the case "$SETUP_OS" in ... block: add
logic that detects or sets a safe default for SETUP_OS (e.g., compute from uname
or read from an env var with a fallback) and assign it to the SETUP_OS variable
prior to the case statement (refer to the SETUP_OS variable and the case
"$SETUP_OS" in the script) so the script won't exit under set -u when SETUP_OS
is unset.
---
Outside diff comments:
In `@runs/00-system-update`:
- Around line 46-55: The verification loop using log_info/log_success/log_error
and has_cmd currently does not cause a non-zero exit when packages are missing;
modify the loop to track failures (e.g., a missing_count or missing_packages
list) and increment/append inside the else branch where log_error is called,
then after the for loop check that tracker and if any failures exist call
log_error summarizing the missing packages and exit 1 so the module fails fast;
update the functions/variables referenced (has_cmd, log_error, log_success)
accordingly.
---
Nitpick comments:
In `@runs/10-core-cli`:
- Around line 17-19: The two identical install blocks duplicate the same
pkg_install call; update the conditional(s) that check SETUP_OS so both "arch"
and "macos" fall through to a single pkg_install invocation instead of
duplicated blocks — e.g., consolidate the separate if [[ "$SETUP_OS" == "arch"
]]; then ... fi and the macOS block into one conditional that tests SETUP_OS for
"arch" OR "macos" and calls pkg_install wget tree cloc htop vim fastfetch bat
fzf eza once; keep the SETUP_OS variable and pkg_install symbol names unchanged
so other logic still references them correctly.
In `@runs/20-shell`:
- Around line 54-67: Update the git clone calls that install the zsh plugins to
perform shallow clones by adding the --depth 1 option; specifically modify the
two git clone invocations that install "zsh-autosuggestions" and
"zsh-syntax-highlighting" (invoked via run_cmd) so they include --depth 1 to
speed up setup and reduce bandwidth.
In `@runs/30-git-ssh`:
- Around line 67-68: The script always starts a new ssh-agent via eval
"$(ssh-agent -s)" which spawns agents unnecessarily; modify the logic around
ssh-agent and ssh-add (the run_cmd and log_warn calls) to first check
SSH_AUTH_SOCK and only start a new agent when SSH_AUTH_SOCK is empty or points
to a dead socket, then proceed to run_cmd ssh-add "$SSH_KEY_PATH" and fallback
to log_warn on failure—ensure the check is performed before invoking ssh-agent
so you won't spawn extra agents on subsequent runs.
In `@runs/80-dotfiles`:
- Around line 39-46: The symlink management file still contains a TODO log_info
instead of actual mappings; replace the log_info "TODO..." line with concrete
ensure_symlink calls for your common dotfiles using the existing helper (e.g.,
call ensure_symlink "$DOTFILES_DIR/.zshrc" "$HOME/.zshrc", ensure_symlink
"$DOTFILES_DIR/.gitconfig" "$HOME/.gitconfig", ensure_symlink
"$DOTFILES_DIR/.config/starship.toml"
"${XDG_CONFIG_HOME:-$HOME/.config}/starship.toml", plus mappings for
editors/terminals like "$DOTFILES_DIR/.config/nvim" and
"$DOTFILES_DIR/.config/kitty" as needed), ensuring you reference DOTFILES_DIR
and XDG_CONFIG_HOME exactly and remove the placeholder log_info line so the
script actually creates the symlinks.
In `@runs/99-manual`:
- Around line 14-38: Replace the repeated echo lines with a single heredoc block
after the existing log_info call: keep the "log_info \"The following items
require manual action:\"" call, then open a heredoc and place the entire
checklist (all numbered items, arrows like "→", blank lines and the reference to
"runs/80-dotfiles") inside it, then close the heredoc; this removes the multiple
echo calls and preserves the exact output/formatting while making the checklist
easier to maintain.
In `@scripts/dev-setup`:
- Around line 32-41: The case branches for SETUP_OS are redundant — collapse the
identical arch, ubuntu, debian, and macos branches into a single pattern branch
that calls pkg_install "${MISSING[@]}" (e.g., arch|ubuntu|debian|macos) )
pkg_install "${MISSING[@]}" ;; — keep any existing OS validation/unsupported
fallback in the case statement/else branch so unsupported SETUP_OS values still
produce an error.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: c0fce5ce-ec5f-44c6-b676-a19526069bcf
📒 Files selected for processing (19)
docs/01-architecture.mddocs/03-implementation-plan.mddocs/08-milestone-1-arch-mvp.mdlib/commonrunruns/00-system-updateruns/10-core-cliruns/20-shellruns/30-git-sshruns/40-firewallruns/50-browserruns/80-dotfilesruns/90-dev-qualityruns/99-manualscripts/dev-setupscripts/linttests/README.mdtests/docker-archtests/docker-ubuntu
✅ Files skipped from review due to trivial changes (4)
- docs/03-implementation-plan.md
- docs/01-architecture.md
- docs/08-milestone-1-arch-mvp.md
- tests/README.md
🚧 Files skipped from review as they are similar to previous changes (1)
- lib/common
|
@coderabbitai rate limit |
|
Review rate limit: 0/1 reviews remaining, refill in 26 minutes and 39 seconds. |
… harden setup module checks
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@scripts/lint`:
- Around line 25-28: The remediation message printed when required tools are
missing currently tells users to run "./scripts/dev-setup"; update that message
to the correct command "./run --only dev-quality" (the echo that prints "Run
./scripts/dev-setup to install them." in the scripts/lint flow) so the user is
directed to the repo's actual install path referenced by runs/90-dev-quality and
the earlier hint on Line 5.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: f4ba3a46-0908-458b-a5f3-3d42cd24ebd6
📒 Files selected for processing (7)
runs/00-system-updateruns/20-shellruns/30-git-sshruns/40-firewallruns/80-dotfilesruns/90-dev-qualityscripts/lint
🚧 Files skipped from review as they are similar to previous changes (6)
- runs/90-dev-quality
- runs/20-shell
- runs/40-firewall
- runs/00-system-update
- runs/80-dotfiles
- runs/30-git-ssh
Summary by CodeRabbit
New Features
--dry-run,--only, and--skipflags for flexible and granular module execution control.Tests
Documentation