Skip to content

Misc fixes by Mistral#21

Open
fortes wants to merge 2 commits intomainfrom
mistral-fixes
Open

Misc fixes by Mistral#21
fortes wants to merge 2 commits intomainfrom
mistral-fixes

Conversation

@fortes
Copy link
Owner

@fortes fortes commented Dec 10, 2025

No description provided.

Copilot AI review requested due to automatic review settings December 10, 2025 01:47
@gemini-code-assist
Copy link

Summary of Changes

Hello @fortes, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on enhancing the reliability and efficiency of various installation scripts within the repository. By introducing idempotency checks for GitHub and Node.js package installations, and strengthening the stow script with comprehensive pre-flight validations and safer argument handling, the changes ensure a more stable and predictable setup process for dotfiles and development tools.

Highlights

  • Idempotent Package Installation: The install_github_packages and install_node_packages scripts now include checks to determine if a tool or package is already installed before attempting re-installation. This prevents redundant operations and ensures the scripts can be run multiple times without unnecessary downloads or installations.
  • Robust stow Script Enhancements: The stow script has been significantly improved with pre-checks for the availability of the stow command, validation of stowed-files and target directories, and a more robust method for discovering and handling packages using safe array expansion.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces several useful fixes, primarily adding idempotency checks to installation scripts to avoid re-installing software that is already present. The changes are generally good, but I've found a few critical and high-severity issues in the implementation of these checks that could cause them to fail or behave incorrectly. My review includes suggestions to fix a critical bug in the stow script that would prevent it from working, and to correct faulty logic in the package-checking mechanisms in install_github_packages and install_node_packages.

script/stow Outdated
local packages=()
while IFS= read -r -d '' package; do
packages+=("${package}")
done < <(find "${stowed_files_path}" -mindepth 1 -maxdepth 1 -type d -print0)

Choose a reason for hiding this comment

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

critical

The find command currently returns the full path for each package directory. However, stow expects only the package names (i.e., the directory basenames) relative to the directory specified with --dir. Passing full paths will cause the stow command to fail with an error like stow: ERROR: The stow directory ... does not contain package ....

You can use find's -printf '%f\0' action to print only the filename, which is more efficient than calling basename in a loop.

  done < <(find "${stowed_files_path}" -mindepth 1 -maxdepth 1 -type d -printf '%f\0')

local install_location="$HOME/.local/share/lua-language-server"

# Check if already installed
if [[ -d "${install_location}" ]] && [[ -n "$(find "${install_location}" -type f -name "bin/*" 2>/dev/null)" ]]; then

Choose a reason for hiding this comment

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

high

The find command used to check if lua-language-server is already installed is incorrect. The -name "bin/*" argument will cause find to look for a file literally named bin/*, which is unlikely to exist. This means the check will always fail, and the script will attempt to reinstall the package on every run.

A more correct and efficient approach would be to check for the specific executable, as its path within the extracted archive is predictable.

  if [[ -x "${install_location}/bin/lua-language-server" ]]; then

Comment on lines 80 to 89
local missing_packages=()
for package in "${PACKAGES[@]}"; do
# Extract package name (remove @scope/ if present)
local package_name="${package#*/}"
package_name="${package_name%%@*}" # Remove version if present

if ! pnpm list --global | grep -q "${package_name}"; then
missing_packages+=("${package}")
fi
done

Choose a reason for hiding this comment

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

high

The current logic for checking installed node packages is inefficient and can be unreliable.

  1. Inefficiency: pnpm list --global is executed inside the for loop, which is inefficient for a large number of packages.
  2. Incorrect Package Name: Stripping the scope from packages (e.g., @foo/bar becomes bar) with local package_name="${package#*/}" is incorrect and can lead to name collisions.
  3. False Positives: The grep command can match substrings, leading to false positives. For example, checking for rome could incorrectly match an installed package named chrome.

A more robust approach is to fetch the list of packages once, not strip the scope, and use a more precise grep to match the full package name at the beginning of a line.

  local missing_packages=()
  # Get a flat list of globally installed packages once to be efficient.
  # Redirect stderr to avoid errors if no packages are installed, and use `|| true` to prevent script exit.
  local installed_list
  installed_list="$(pnpm list --global --depth=0 2>/dev/null || true)"

  for package in "${PACKAGES[@]}"; do
    # Extract package name, removing only the version specifier.
    local package_name_no_version="${package%%@*}"

    # Check for an exact match at the beginning of a line, followed by a space.
    if ! echo "${installed_list}" | grep -q -E "^${package_name_no_version} "; then
      missing_packages+=("${package}")
    fi
  done

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds robustness improvements and idempotency checks to installation scripts, allowing them to skip already-installed packages and handle error conditions more gracefully.

  • Enhanced validation with checks for required commands and directories
  • Added skip logic to avoid reinstalling already-present packages
  • Improved error handling with clearer error messages and early returns

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
script/stow Adds stow command availability check, converts warning to error for missing stowed-files directory, validates target directory, and uses find to build package list instead of ls
script/install_node_packages Adds check to skip Node LTS installation if already present, implements package-by-package checking to only install missing global packages
script/install_github_packages Adds existence checks to skip installation in install_bin, install_tarball, install_zip, install_lua_language_server, install_neovim_stable, and install_yazi functions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if [[ "$(uname -m)" == "aarch64" ]]; then
fnm install --lts --arch arm64
# Check if node LTS is already installed
if fnm list | grep -q "lts/latest"; then
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

The grep pattern "lts/latest" doesn't match the actual output format of fnm list. The command fnm list typically shows versions like v20.11.0 lts-latest or v20.11.0 (lts/iron), not lts/latest.

Consider using a more robust check:

if fnm list | grep -q "lts-latest"; then

Or better yet, check if any LTS version is installed:

if fnm list | grep -qE '\(lts/|lts-latest'; then
Suggested change
if fnm list | grep -q "lts/latest"; then
if fnm list | grep -qE "\(lts/|lts-latest"; then

Copilot uses AI. Check for mistakes.
Comment on lines 82 to 84
# Extract package name (remove @scope/ if present)
local package_name="${package#*/}"
package_name="${package_name%%@*}" # Remove version if present
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

The package name extraction logic is incorrect for scoped packages. For a package like @anthropic-ai/claude-code:

  • Line 83 ${package#*/} removes everything before the first /, giving claude-code
  • But for unscoped packages like neovim, it returns neovim unchanged (correct)
  • This breaks the grep check on line 86 for unscoped packages

The logic should handle both scoped and unscoped packages:

local package_name="${package%%@*}"  # Remove version if present
if [[ "${package_name}" == *"/"* ]]; then
  package_name="${package_name#*/}"  # Remove scope for scoped packages
fi
Suggested change
# Extract package name (remove @scope/ if present)
local package_name="${package#*/}"
package_name="${package_name%%@*}" # Remove version if present
# Extract package name (handle scoped/unscoped, remove version if present)
local package_name="${package%%@*}" # Remove version if present
if [[ "${package_name}" == *"/"* ]]; then
package_name="${package_name#*/}" # Remove scope for scoped packages
fi

Copilot uses AI. Check for mistakes.
local install_location="$HOME/.local/share/lua-language-server"

# Check if already installed
if [[ -d "${install_location}" ]] && [[ -n "$(find "${install_location}" -type f -name "bin/*" 2>/dev/null)" ]]; then
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

The find command has an incorrect -name pattern. The pattern "bin/*" will never match because -name only matches the basename of files, not paths. This means the check will always fail to detect an existing installation.

The pattern should be:

if [[ -d "${install_location}" ]] && [[ -f "${install_location}/bin/lua-language-server" ]]; then

Alternatively, if you want to check for any files in the bin directory:

if [[ -d "${install_location}/bin" ]] && [[ -n "$(find "${install_location}/bin" -type f 2>/dev/null)" ]]; then
Suggested change
if [[ -d "${install_location}" ]] && [[ -n "$(find "${install_location}" -type f -name "bin/*" 2>/dev/null)" ]]; then
if [[ -d "${install_location}/bin" ]] && [[ -n "$(find "${install_location}/bin" -type f 2>/dev/null)" ]]; then

Copilot uses AI. Check for mistakes.
# Get list of packages to stow
local packages=()
while IFS= read -r -d '' package; do
packages+=("${package}")
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

The find command returns full paths (e.g., /path/to/stowed-files/package1), but stow expects package names (basenames) relative to the --dir argument. This will cause stow to fail because it won't be able to find packages with full paths.

Fix by extracting the basename:

while IFS= read -r -d '' package; do
  packages+=("$(basename "${package}")")
done < <(find "${stowed_files_path}" -mindepth 1 -maxdepth 1 -type d -print0)
Suggested change
packages+=("${package}")
packages+=("$(basename "${package}")")

Copilot uses AI. Check for mistakes.
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