Skip to content

feat: add fish wrapper functions for local scripts and move yek to cargo globals - #1358

Merged
shunkakinoki merged 2 commits into
mainfrom
feat/fish-script-wrappers
Apr 5, 2026
Merged

feat: add fish wrapper functions for local scripts and move yek to cargo globals#1358
shunkakinoki merged 2 commits into
mainfrom
feat/fish-script-wrappers

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Apr 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add fish functions wrapping 6 local scripts (sync-local-binaries, install-cargo-globals, install-npm-globals, install-uv-globals, update-local-binaries, llm-update) with abbreviations: slb, icg, ing, iug, ulb, llmu
  • Move yek from custom GitHub release installer to Cargo.toml (yek = "0.22.1") - yek is on crates.io, no need for a custom download script
  • Remove yek module (5 files), shim scripts, and 3 related spec files
  • Add auto-switch.sh coverage entry and spec

Test plan

  • make shell-lint passes (0 errors)
  • make shell-test passes (914 shellspec examples, 265 fish tests)

Summary by cubic

Add fish wrapper functions for six local scripts with short abbreviations, and add an auto-switch for Claude accounts on rate limits via claude-swap. Move yek to a Cargo-managed dependency and remove the custom installer and related tests.

  • New Features

    • Fish wrappers with abbreviations: slb (sync-local-binaries), icg (install-cargo-globals), ing (install-npm-globals), iug (install-uv-globals), ulb (update-local-binaries), llmu (llm-update).
    • Claude auto-switch on rate limits: StopFailure hook runs $HOME/.claude/hooks/auto-switch.sh to call cswap --switch when 429/rate-limit patterns are detected (requires cswap and ≥2 accounts).
  • Refactors

    • Replace custom yek installer with Cargo dep yek = "0.22.1"; remove home-manager/modules/yek shims and specs.
    • Add claude-swap>=1.1.5 to pyproject.toml; update coverage and add specs for the new hook and fish wrappers.

Written for commit b2f5e1f. Summary will update on new commits.

- Add StopFailure hook that detects rate limit errors and runs
  cswap --switch to rotate to the next Claude account
- Add claude-swap to uv global tools (pyproject.toml)
- Hook reads error/error_details from stdin, only triggers on
  rate_limit/429/overloaded/quota patterns
…rgo globals

- Add fish functions wrapping sync-local-binaries, install-cargo-globals,
  install-npm-globals, install-uv-globals, update-local-binaries, llm-update
- Register abbreviations: slb, icg, ing, iug, ulb, llmu
- Move yek from custom GitHub release installer to Cargo.toml (yek 0.22.1)
- Remove yek module, shim scripts, and related specs
- Add auto-switch.sh coverage entry and spec
Copilot AI review requested due to automatic review settings April 5, 2026 06:31
@mesa-dot-dev

mesa-dot-dev Bot commented Apr 5, 2026

Copy link
Copy Markdown

You do not have enough credits to review this pull request. Please purchase more credits to continue.

@coderabbitai

coderabbitai Bot commented Apr 5, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b2de13a4-3898-4032-b5a8-554af1a4ad48

📥 Commits

Reviewing files that changed from the base of the PR and between 04654b1 and b2f5e1f.

📒 Files selected for processing (28)
  • Cargo.toml
  • config/claude/hooks/auto-switch.sh
  • config/claude/settings.json
  • home-manager/modules/default.nix
  • home-manager/modules/yek/default.nix
  • home-manager/modules/yek/install-yek-shim.sh
  • home-manager/modules/yek/install-yek.sh
  • home-manager/modules/yek/yek-shim.sh
  • home-manager/modules/yek/yek.sh
  • home-manager/programs/fish/default.nix
  • home-manager/programs/fish/functions/_install_cargo_globals_function.fish
  • home-manager/programs/fish/functions/_install_npm_globals_function.fish
  • home-manager/programs/fish/functions/_install_uv_globals_function.fish
  • home-manager/programs/fish/functions/_llm_update_function.fish
  • home-manager/programs/fish/functions/_sync_local_binaries_function.fish
  • home-manager/programs/fish/functions/_update_local_binaries_function.fish
  • pyproject.toml
  • spec/auto_switch_spec.sh
  • spec/coverage_spec.sh
  • spec/fish/_install_cargo_globals_function_test.fish
  • spec/fish/_install_npm_globals_function_test.fish
  • spec/fish/_install_uv_globals_function_test.fish
  • spec/fish/_llm_update_function_test.fish
  • spec/fish/_sync_local_binaries_function_test.fish
  • spec/fish/_update_local_binaries_function_test.fish
  • spec/install_yek_shim_spec.sh
  • spec/yek_shim_spec.sh
  • spec/yek_spec.sh

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added automatic account switching when rate limits are encountered.
    • Added shell shortcuts (icg, ing, iug, llmu, slb, ulb) for managing global packages and local binaries.
  • Chores

    • Updated dependencies: added claude-swap and yek crate support.
    • Removed Home Manager-based tool installation module.
  • Tests

    • Added test coverage for new shell functions and account-switching behavior.

Walkthrough

The PR removes the Home Manager yek module and its installation infrastructure while adding yek as a direct Cargo dependency. It introduces a Claude rate-limit auto-switch hook that detects error conditions and triggers account switching via cswap. Six new fish shell abbreviations and their corresponding wrapper functions are added to invoke package management and update scripts. Test coverage is updated to reflect these changes.

Changes

Cohort / File(s) Summary
Dependency Updates
Cargo.toml, pyproject.toml
Added yek crate (v0.22.1) and claude-swap (≥1.1.5) tool dependency.
Claude Auto-Switch Hook
config/claude/hooks/auto-switch.sh, config/claude/settings.json, spec/auto_switch_spec.sh
New hook script detects rate-limit errors from Claude and triggers cswap --switch to rotate accounts. Hook configured in settings with 10s timeout on StopFailure event.
Fish Shell Functions
home-manager/programs/fish/default.nix, home-manager/programs/fish/functions/_install_cargo_globals_function.fish, home-manager/programs/fish/functions/_install_npm_globals_function.fish, home-manager/programs/fish/functions/_install_uv_globals_function.fish, home-manager/programs/fish/functions/_llm_update_function.fish, home-manager/programs/fish/functions/_sync_local_binaries_function.fish, home-manager/programs/fish/functions/_update_local_binaries_function.fish
Added six wrapper functions with abbreviations (icg, ing, iug, llmu, slb, ulb) that delegate to external scripts for package/binary management and LLM config updates.
Fish Function Tests
spec/fish/_install_cargo_globals_function_test.fish, spec/fish/_install_npm_globals_function_test.fish, spec/fish/_install_uv_globals_function_test.fish, spec/fish/_llm_update_function_test.fish, spec/fish/_sync_local_binaries_function_test.fish, spec/fish/_update_local_binaries_function_test.fish
New Fish test suite validating that each wrapper function exits with status 1 when target scripts are missing.
Yek Module Removal
home-manager/modules/default.nix, home-manager/modules/yek/default.nix, home-manager/modules/yek/install-yek-shim.sh, home-manager/modules/yek/install-yek.sh, home-manager/modules/yek/yek-shim.sh, home-manager/modules/yek/yek.sh
Removed entire Home Manager yek module including Nix derivation, installation scripts, and wrapper shims previously used for GitHub release downloads.
Test Coverage Updates
spec/coverage_spec.sh, spec/install_yek_shim_spec.sh, spec/yek_shim_spec.sh, spec/yek_spec.sh
Updated coverage assertions: added auto-switch hook spec requirement, added new fish function scripts to covered list, removed four yek module test suites.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

enhancement, dependencies

Poem

🐰 The yek module says goodbye,
As cargo makes it fly so high,
Rate limits met with swift account swap,
Fish abbreviations make workflows stop,
New helpers bloom where old ones dropped! 🎉

✨ 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/fish-script-wrappers

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 and usage tips.

@shunkakinoki
shunkakinoki merged commit d1698db into main Apr 5, 2026
28 of 34 checks passed
@shunkakinoki
shunkakinoki deleted the feat/fish-script-wrappers branch April 5, 2026 06:32
@mesa-dot-dev

mesa-dot-dev Bot commented Apr 5, 2026

Copy link
Copy Markdown

Mesa Description

TL;DR

Added fish wrapper functions for frequently used local scripts, streamlined yek installation by moving it to Cargo.toml, and removed associated custom installation files.

What changed?

  • Added fish functions wrapping 6 local scripts (sync-local-binaries, install-cargo-globals, install-npm-globals, install-uv-globals, update-local-binaries, llm-update) with abbreviations: slb, icg, ing, iug, ulb, llmu.
  • Moved yek from a custom GitHub release installer to Cargo.toml (yek = "0.22.1").
  • Removed the yek module (5 files), shim scripts, and 3 related spec files.
  • Added auto-switch.sh coverage entry and spec.

Description generated by Mesa. Update settings

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request implements an automatic Claude account switcher for rate-limit handling via a new hook script and the claude-swap utility. It also replaces the custom yek module with a direct dependency and adds several Fish shell functions for managing global packages and local binaries. Reviewers suggested improving the hook script's robustness by checking for jq and using herestrings, and recommended directing error output to stderr in the new Fish functions.

Comment on lines +11 to +13
if ! command -v cswap &>/dev/null; then
exit 0
fi

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.

medium

The script relies on jq to parse the hook input. It is safer to check for its availability alongside cswap to avoid silent failures if jq is missing in the environment.

Suggested change
if ! command -v cswap &>/dev/null; then
exit 0
fi
if ! command -v cswap &>/dev/null || ! command -v jq &>/dev/null; then
exit 0
fi

Comment on lines +23 to +24
ERROR=$(echo "$INPUT" | jq -r '.error // empty' 2>/dev/null) || true
ERROR_DETAILS=$(echo "$INPUT" | jq -r '.error_details // empty' 2>/dev/null) || true

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.

medium

Using herestrings (<<< "$INPUT") is generally preferred over echo "$INPUT" | jq as it avoids a subshell and is safer if the input starts with a hyphen (which echo might interpret as a flag).

Suggested change
ERROR=$(echo "$INPUT" | jq -r '.error // empty' 2>/dev/null) || true
ERROR_DETAILS=$(echo "$INPUT" | jq -r '.error_details // empty' 2>/dev/null) || true
ERROR=$(jq -r '.error // empty' 2>/dev/null <<< "$INPUT") || true
ERROR_DETAILS=$(jq -r '.error_details // empty' 2>/dev/null <<< "$INPUT") || true

function _install_cargo_globals_function --description "Install global Cargo packages"
set -l script "$HOME/dotfiles/home-manager/modules/cargo-globals/install-cargo-globals.sh"
if not test -f "$script"
echo "install-cargo-globals.sh not found at $script"

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.

medium

Error messages should be directed to stderr (>&2) to distinguish them from regular command output. This applies to the other new fish functions as well.

        echo "install-cargo-globals.sh not found at $script" >&2

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR adds fish-shell convenience wrappers for several local maintenance scripts, introduces an auto-switch hook for Claude rate-limit failures, and simplifies installation of yek by using Cargo globals instead of a custom GitHub-release installer.

Changes:

  • Add fish functions + abbreviations wrapping 6 local scripts (slb, icg, ing, iug, ulb, llmu) and fish tests for missing-script behavior
  • Add auto-switch.sh hook + spec + coverage entry; add claude-swap dependency
  • Remove the custom yek Nix module + installer/shim scripts and related specs; add yek = "0.22.1" to Cargo.toml

Reviewed changes

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

Show a summary per file
File Description
spec/yek_spec.sh Removes specs for the deleted custom yek installer + wrapper scripts
spec/yek_shim_spec.sh Removes specs for the deleted yek shim
spec/install_yek_shim_spec.sh Removes specs for the deleted install-yek shim
spec/fish/_update_local_binaries_function_test.fish Adds fish test for _update_local_binaries_function missing-script behavior
spec/fish/_sync_local_binaries_function_test.fish Adds fish test for _sync_local_binaries_function missing-script behavior
spec/fish/_llm_update_function_test.fish Adds fish test for _llm_update_function missing-script behavior
spec/fish/_install_uv_globals_function_test.fish Adds fish test for _install_uv_globals_function missing-script behavior
spec/fish/_install_npm_globals_function_test.fish Adds fish test for _install_npm_globals_function missing-script behavior
spec/fish/_install_cargo_globals_function_test.fish Adds fish test for _install_cargo_globals_function missing-script behavior
spec/coverage_spec.sh Updates coverage list/spec presence checks: adds auto-switch.sh, removes yek scripts
spec/auto_switch_spec.sh Adds a spec for auto-switch.sh “no cswap => exit 0” behavior
pyproject.toml Adds claude-swap dependency used by the new hook
home-manager/programs/fish/functions/_update_local_binaries_function.fish Adds fish wrapper to run update-local-binaries.sh
home-manager/programs/fish/functions/_sync_local_binaries_function.fish Adds fish wrapper to run sync-local-binaries.sh
home-manager/programs/fish/functions/_llm_update_function.fish Adds fish wrapper to run llm-update.sh
home-manager/programs/fish/functions/_install_uv_globals_function.fish Adds fish wrapper to run install-uv-globals.sh
home-manager/programs/fish/functions/_install_npm_globals_function.fish Adds fish wrapper to run install-npm-globals.sh
home-manager/programs/fish/functions/_install_cargo_globals_function.fish Adds fish wrapper to run install-cargo-globals.sh
home-manager/programs/fish/default.nix Wires new fish functions into abbreviations and function list
home-manager/modules/yek/yek.sh Deletes the custom yek wrapper (now installed via Cargo globals)
home-manager/modules/yek/yek-shim.sh Deletes the custom yek shim
home-manager/modules/yek/install-yek.sh Deletes the GitHub-release installer script for yek
home-manager/modules/yek/install-yek-shim.sh Deletes the custom install-yek shim
home-manager/modules/yek/default.nix Deletes the custom Nix module that installed/activated yek
home-manager/modules/default.nix Removes the yek module from the modules list
config/claude/settings.json Adds StopFailure hook to run auto-switch.sh
config/claude/hooks/auto-switch.sh Adds hook that switches accounts on rate-limit-like errors
Cargo.toml Adds yek = "0.22.1" as a Cargo global dependency

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

fi

# Require at least 2 managed accounts
ACCOUNT_COUNT=$(cswap --list 2>/dev/null | grep -c '^\s*[0-9]' || echo 0)

Copilot AI Apr 5, 2026

Copy link

Choose a reason for hiding this comment

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

grep -c '^\s*[0-9]' is not doing what it looks like: \s isn’t a portable whitespace escape in grep BRE/ERE, so it will typically be treated as a literal s. Also, grep -c prints 0 even when it exits 1 (no matches); combined with set -o pipefail, the || echo 0 branch can run and append a second 0, producing a non-numeric ACCOUNT_COUNT (e.g., 0\n0) and breaking the -lt comparison. Use a portable whitespace class (e.g. [[:space:]]) and avoid appending output on “no matches” (e.g. || true), ensuring the command substitution always evaluates to a single integer.

Suggested change
ACCOUNT_COUNT=$(cswap --list 2>/dev/null | grep -c '^\s*[0-9]' || echo 0)
ACCOUNT_COUNT=$(cswap --list 2>/dev/null | grep -c '^[[:space:]]*[0-9]' || true)

Copilot uses AI. Check for mistakes.
case "${ERROR}${ERROR_DETAILS}" in
*rate_limit*|*rate-limit*|*rate\ limit*|*overloaded*|*too_many_requests*|*429*|*quota*|*capacity*)
echo "[$(date)] Auto-switching Claude account due to rate limit" >&2
cswap --switch 2>&1 | head -5 >&2

Copilot AI Apr 5, 2026

Copy link

Choose a reason for hiding this comment

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

With set -euo pipefail, a failing cswap --switch (or a broken pipe from head) can cause this hook itself to exit non-zero, which is risky for a “best effort” remediation hook triggered during failures. Consider making the switch attempt explicitly non-fatal (e.g., append || true, or temporarily disable -e/pipefail around the pipeline) so the hook doesn’t introduce additional failure modes.

Suggested change
cswap --switch 2>&1 | head -5 >&2
cswap --switch 2>&1 | head -5 >&2 || true

Copilot uses AI. Check for mistakes.
Comment thread spec/auto_switch_spec.sh
Comment on lines +8 to +9
# Mock command so cswap is not found
command() { return 1; }

Copilot AI Apr 5, 2026

Copy link

Choose a reason for hiding this comment

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

The command() { return 1; } definition on line 9 is not used by the When run ... invocation (which runs in a separate bash -c and redefines command again). Removing the outer definition avoids confusion and keeps the spec focused on the behavior under test.

Suggested change
# Mock command so cswap is not found
command() { return 1; }

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.

2 participants