Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions bin/omarchy-mise-install
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,32 @@ esac

mkdir -p "$HOME/.local/bin"

# Append @latest only when the spec has no version. npm:@scope/name uses @
# for the scope, so that form still needs @latest; tool@1.2.3 does not.
# A spec with [options] takes it after them, as in http:muse[...]@latest, so
# only what follows them can be a version; an @ inside them is part of a URL.
version=${package##*]}
if [[ $version == *@latest || $version == npm:@*/*@* ]]; then
spec=$package
elif [[ $version == npm:@*/* ]]; then
spec="$package@latest"
elif [[ $version == *@* ]]; then
spec=$package
else
spec="$package@latest"
fi

# The heredoc below is unquoted, so whatever these hold is written into the
# wrapper as shell source. Quote them the way omarchy-install-and-launch does, so
# a package name carrying shell characters stays one argument instead of running.
printf -v package_arg '%q' "$package"
printf -v package_arg '%q' "$spec"
printf -v bin_arg '%q' "$bin"

# Keep values that are inert inside double quotes in the form existing migrations
# recognize, including mise backend options that %q would unnecessarily escape.
case "$package" in
case "$spec" in
*'$'* | *'`'* | *'"'* | *'\'* | *'!'* | *[[:cntrl:]]*) ;;
*) package_arg="\"$package\"" ;;
*) package_arg="\"$spec\"" ;;
esac
case "$bin" in
*'$'* | *'`'* | *'"'* | *'\'* | *'!'* | *[[:cntrl:]]*) ;;
Expand Down
4 changes: 2 additions & 2 deletions bin/omarchy-remove-preinstalls
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ if gum confirm "Are you sure you want to remove all preinstalled web apps, TUI w

# Preserve a user-managed Kimi launcher at the same path.
if [[ -f ~/.local/bin/kimi && ! -L ~/.local/bin/kimi ]] &&
grep -Eq '^mise use -g .*"npm:@moonshot-ai/kimi-code"' ~/.local/bin/kimi; then
grep -Eq '^mise use -g .*"npm:@moonshot-ai/kimi-code(@latest)?"' ~/.local/bin/kimi; then
rm -f ~/.local/bin/kimi
fi

# Cursor's own installer links ~/.local/bin/cursor-agent as well, so only
# the mise wrapper omarchy-mise-install wrote is a preinstall.
if [[ -f ~/.local/bin/cursor-agent && ! -L ~/.local/bin/cursor-agent ]] &&
grep -Eq '^mise use -g .*"cursor-agent"' ~/.local/bin/cursor-agent; then
grep -Eq '^mise use -g .*"cursor-agent(@latest)?"' ~/.local/bin/cursor-agent; then
rm -f ~/.local/bin/cursor-agent
fi

Expand Down
2 changes: 1 addition & 1 deletion migrations/1785846769.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ if [[ ! -f $HOME/.local/state/omarchy/preinstalls-removed ]]; then
omarchy-mise-install github:can1357/oh-my-pi omp
omarchy-mise-install npm:@xai-official/grok grok
omarchy-mise-install crush
elif [[ -f $HOME/.local/bin/omp ]] && grep -Eq 'mise use -g .*"oh-my-pi"' "$HOME/.local/bin/omp"; then
elif [[ -f $HOME/.local/bin/omp ]] && grep -Eq 'mise use -g .*"oh-my-pi(@latest)?"' "$HOME/.local/bin/omp"; then
rm -f "$HOME/.local/bin/omp"
fi
2 changes: 1 addition & 1 deletion migrations/1786719479.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fi
# Remove Preinstalls no longer lists gemini, so Omarchy's own wrapper would
# linger with nothing left to clean it up. Anchored to the line the installer
# writes, so a hand-written wrapper that merely mentions it is left alone.
if [[ -f $HOME/.local/bin/gemini ]] && grep -Eq '^mise use -g .*"gemini"' "$HOME/.local/bin/gemini"; then
if [[ -f $HOME/.local/bin/gemini ]] && grep -Eq '^mise use -g .*"gemini(@latest)?"' "$HOME/.local/bin/gemini"; then
rm -f "$HOME/.local/bin/gemini"
fi

Expand Down
29 changes: 29 additions & 0 deletions migrations/1789093830.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
echo "Refresh mise wrappers so they resolve @latest on each run"

# omarchy-mise-install now writes `mise use -g --quiet "<tool>@latest"` so a
# wrapper cannot stay pinned on a stale installed version. Wrappers already on
# disk still call the bare tool name (e.g. claude@latest is the target form).
# Rewrite the exact --quiet template through omarchy-mise-install.

stale_quiet_template() {
printf '#!/bin/bash\nexport MISE_MINIMUM_RELEASE_AGE=0\nmise use -g --quiet "%s" || exit 1\nexec mise x "%s" -- "%s" "$@"' "$1" "$1" "$2"
}

bin_dir="$HOME/.local/bin"

[[ -d $bin_dir ]] || exit 0

for wrapper in "$bin_dir"/*; do
[[ -f $wrapper && ! -L $wrapper && -r $wrapper ]] || continue
(($(stat -c%s "$wrapper") <= 1024)) || continue

contents=$(<"$wrapper")
package=$(sed -n 's/^mise use -g --quiet "\(.*\)" || exit 1$/\1/p' <<<"$contents")
bin=$(sed -n 's/^exec mise x ".*" -- "\(.*\)" "\$@"$/\1/p' <<<"$contents")
Comment on lines +21 to +22

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.

P2 Escaped wrappers remain stale. If an existing wrapper has a shell-special character in its package or binary name, the installer writes that argument with shell escaping instead of double quotes. These patterns then skip the wrapper, so it keeps using its bare spec and may remain on an older installed version. Please handle the escaped form as well.


[[ -n $package && -n $bin ]] || continue
[[ $package == *@latest ]] && continue
[[ $contents == "$(stale_quiet_template "$package" "$bin")" ]] || continue

omarchy-mise-install "$package" "${wrapper##*/}" "$bin"
done
17 changes: 9 additions & 8 deletions test/shell.d/default-agent-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,24 @@ muse_package="http:muse[url=https://api.meta.ai/muse-launcher.sh,bin=muse,versio
assert_lazy_stub() {
local package=$1
local command=$2
local spec=${3:-$package}

: >"$mise_history"
"$ROOT/bin/omarchy-mise-install" "$package" "$command"
"$test_home/.local/bin/$command" --version
mapfile -t mise_calls <"$mise_history"

[[ ${mise_calls[0]} == "use -g --quiet $package" && ${mise_calls[1]} == "x $package -- $command --version" ]] ||
[[ ${mise_calls[0]} == "use -g --quiet $spec" && ${mise_calls[1]} == "x $spec -- $command --version" ]] ||
fail "$command lazy stub preserves its mise package"
}

assert_lazy_stub "$grok_package" grok
assert_lazy_stub "$omp_package" omp
assert_lazy_stub "$crush_package" crush
assert_lazy_stub "$ori_package" ori
assert_lazy_stub "$kimi_package" kimi
assert_lazy_stub "$cursor_agent_package" cursor-agent
assert_lazy_stub "$muse_package" muse
assert_lazy_stub "$grok_package" grok "${grok_package}@latest"
assert_lazy_stub "$omp_package" omp "${omp_package}@latest"
assert_lazy_stub "$crush_package" crush "${crush_package}@latest"
assert_lazy_stub "$ori_package" ori "${ori_package}@latest"
assert_lazy_stub "$kimi_package" kimi "${kimi_package}@latest"
assert_lazy_stub "$cursor_agent_package" cursor-agent "${cursor_agent_package}@latest"
assert_lazy_stub "$muse_package" muse "${muse_package}@latest"
pass "custom agent lazy stubs preserve their mise packages"

source "$ROOT/install/user/mise.sh"
Expand Down
2 changes: 1 addition & 1 deletion test/shell.d/kimi-agent-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ apply_kimi migration
cmp -s "$kimi" "$test_tmp/wrapper" || fail "Kimi migration is idempotent"
"$kimi" --prompt 'Review this project'
mapfile -d '' -t args <"$OMARCHY_TEST_MISE_LOG"
[[ ${args[*]} == "use -g --quiet $package x $package -- kimi --prompt Review this project" ]] ||
[[ ${args[*]} == "use -g --quiet $package@latest x $package@latest -- kimi --prompt Review this project" ]] ||
fail "Kimi migration wrapper installs the official package and forwards arguments"
pass "Kimi migration creates a lazy, repeatable wrapper"

Expand Down
4 changes: 2 additions & 2 deletions test/shell.d/mise-install-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ install_wrapper npm:playwright playwright >/dev/null
log="$tmpdir/normal.log"
: >"$log"
OMARCHY_MISE_TEST_LOG="$log" PATH="$stub_bin:$PATH" "$home/.local/bin/playwright" >/dev/null
grep -Fqx $'mise\tuse\t-g\t--quiet\tnpm:playwright' "$log" ||
grep -Fqx $'mise\tuse\t-g\t--quiet\tnpm:playwright@latest' "$log" ||
fail "the wrapper asks mise for the package it was given" "$(cat "$log")"

pass "a normal install writes a wrapper that names its package"
Expand All @@ -54,7 +54,7 @@ OMARCHY_MISE_TEST_LOG="$log" PATH="$stub_bin:$PATH" "$home/.local/bin/hostile" >
fail "a package name with shell characters does not run when the wrapper does" \
"wrapper: $(cat "$home/.local/bin/hostile")"

grep -Fqx $'mise\tuse\t-g\t--quiet\tnpm:pkg$(touch '"$tmpdir"'/PWNED)end' "$log" ||
grep -Fqx $'mise\tuse\t-g\t--quiet\tnpm:pkg$(touch '"$tmpdir"'/PWNED)end@latest' "$log" ||
fail "the package reaches mise whole" "$(cat "$log")"

pass "a package name with shell characters reaches mise as one argument"
Expand Down
88 changes: 88 additions & 0 deletions test/shell.d/mise-wrapper-latest-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

test_dir=$(mktemp -d)
trap 'rm -rf "$test_dir"' EXIT

home="$test_dir/home"
mkdir -p "$home/.local/bin"

HOME="$home" PATH="$ROOT/bin:$PATH" "$ROOT/bin/omarchy-mise-install" claude
wrapper="$home/.local/bin/claude"

grep -qF 'mise use -g --quiet "claude@latest" || exit 1' "$wrapper" ||
fail "mise wrapper pins the tool at @latest" "$(cat "$wrapper")"
grep -qF 'exec mise x "claude@latest" -- "claude" "$@"' "$wrapper" ||
fail "mise wrapper executes the @latest spec" "$(cat "$wrapper")"
pass "mise wrapper refreshes to @latest on each run"

HOME="$home" PATH="$ROOT/bin:$PATH" "$ROOT/bin/omarchy-mise-install" "npm:@kitlangton/ghui" ghui
grep -qF 'mise use -g --quiet "npm:@kitlangton/ghui@latest" || exit 1' "$home/.local/bin/ghui" ||
fail "mise wrapper appends @latest after a scoped npm package" "$(cat "$home/.local/bin/ghui")"
pass "mise wrapper appends @latest after a scoped npm package"

HOME="$home" PATH="$ROOT/bin:$PATH" "$ROOT/bin/omarchy-mise-install" "claude@1.2.3" claude-pinned
grep -qF 'mise use -g --quiet "claude@1.2.3" || exit 1' "$home/.local/bin/claude-pinned" ||
fail "mise wrapper leaves an already-versioned spec alone" "$(cat "$home/.local/bin/claude-pinned")"
if grep -q 'claude@1.2.3@latest' "$home/.local/bin/claude-pinned"; then
fail "mise wrapper does not append @latest onto a pinned version"
fi
pass "mise wrapper leaves an already-versioned spec alone"

HOME="$home" PATH="$ROOT/bin:$PATH" "$ROOT/bin/omarchy-mise-install" "claude@latest" claude-latest
grep -qF 'mise use -g --quiet "claude@latest" || exit 1' "$home/.local/bin/claude-latest" ||
fail "mise wrapper does not double @latest" "$(cat "$home/.local/bin/claude-latest")"
pass "mise wrapper does not double @latest"

HOME="$home" PATH="$ROOT/bin:$PATH" "$ROOT/bin/omarchy-mise-install" \
"http:muse[url=https://example.test/muse.sh,bin=muse]" muse
grep -qF 'mise use -g --quiet "http:muse[url=https://example.test/muse.sh,bin=muse]@latest" || exit 1' "$home/.local/bin/muse" ||
fail "mise wrapper appends @latest after a backend spec's options" "$(cat "$home/.local/bin/muse")"

HOME="$home" PATH="$ROOT/bin:$PATH" "$ROOT/bin/omarchy-mise-install" \
"http:tool[url=https://example.test/@releases/tool.sh]" tool
grep -qF 'mise use -g --quiet "http:tool[url=https://example.test/@releases/tool.sh]@latest" || exit 1' "$home/.local/bin/tool" ||
fail "mise wrapper does not read an @ inside the options as a version" "$(cat "$home/.local/bin/tool")"

HOME="$home" PATH="$ROOT/bin:$PATH" "$ROOT/bin/omarchy-mise-install" \
"http:tool[url=https://example.test/@releases/tool.sh]@1.2.3" tool-pinned
grep -qF 'mise use -g --quiet "http:tool[url=https://example.test/@releases/tool.sh]@1.2.3" || exit 1' "$home/.local/bin/tool-pinned" ||
fail "mise wrapper leaves a version after the options alone" "$(cat "$home/.local/bin/tool-pinned")"
pass "mise wrapper appends @latest after a backend spec's options"

migration="$ROOT/migrations/1789093830.sh"
[[ -f $migration ]] || fail "a migration rewrites existing mise wrappers onto @latest"
pass "a migration rewrites existing mise wrappers onto @latest"

bin_dir="$home/.local/bin"
cat >"$bin_dir/codex" <<'EOF'
#!/bin/bash
export MISE_MINIMUM_RELEASE_AGE=0
mise use -g --quiet "codex" || exit 1
exec mise x "codex" -- "codex" "$@"
EOF
chmod +x "$bin_dir/codex"

cat >"$bin_dir/muse" <<'EOF'
#!/bin/bash
export MISE_MINIMUM_RELEASE_AGE=0
mise use -g --quiet "http:muse[url=https://example.test/muse.sh,bin=muse]" || exit 1
exec mise x "http:muse[url=https://example.test/muse.sh,bin=muse]" -- "muse" "$@"
EOF
chmod +x "$bin_dir/muse"

HOME="$home" PATH="$ROOT/bin:$PATH" bash -euo pipefail "$migration" >/dev/null

grep -qF 'mise use -g --quiet "codex@latest" || exit 1' "$bin_dir/codex" ||
fail "migration rewrites a quiet wrapper onto @latest" "$(cat "$bin_dir/codex")"
grep -qF 'exec mise x "http:muse[url=https://example.test/muse.sh,bin=muse]@latest" -- "muse" "$@"' "$bin_dir/muse" ||
fail "migration rewrites a wrapper whose spec carries options" "$(cat "$bin_dir/muse")"
pass "migration rewrites a quiet wrapper onto @latest"

before=$(cat "$bin_dir/codex")
HOME="$home" PATH="$ROOT/bin:$PATH" bash -euo pipefail "$migration" >/dev/null
[[ $(cat "$bin_dir/codex") == "$before" ]] || fail "latest-wrapper migration is idempotent"
pass "latest-wrapper migration is idempotent"
18 changes: 9 additions & 9 deletions test/shell.d/mise-wrapper-quiet-migration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,33 +65,33 @@ chmod +x "$bin_dir/mise-exec-era" "$bin_dir/bare-exec-era"

run_migration

grep -qF 'mise use -g --quiet "claude" || exit 1' "$bin_dir/claude" ||
grep -qF 'mise use -g --quiet "claude@latest" || exit 1' "$bin_dir/claude" ||
fail "migration adds --quiet to a stale wrapper"
pass "migration adds --quiet to a stale wrapper"

grep -qF 'mise use -g --quiet "github:can1357/oh-my-pi" || exit 1' "$bin_dir/omp" ||
grep -qF 'mise use -g --quiet "github:can1357/oh-my-pi@latest" || exit 1' "$bin_dir/omp" ||
fail "migration keeps a wrapper's package when the command name differs"
grep -qF 'exec mise x "github:can1357/oh-my-pi" -- "omp" "$@"' "$bin_dir/omp" ||
grep -qF 'exec mise x "github:can1357/oh-my-pi@latest" -- "omp" "$@"' "$bin_dir/omp" ||
fail "migration keeps a wrapper's bin name when the command name differs"
pass "migration preserves package and bin names"

grep -qF 'exec mise x "npm:@kitlangton/ghui" -- "ghui" "$@"' "$bin_dir/ghui" ||
grep -qF 'exec mise x "npm:@kitlangton/ghui@latest" -- "ghui" "$@"' "$bin_dir/ghui" ||
fail "migration preserves a scoped npm package name"
pass "migration preserves a scoped npm package name"

grep -qF 'mise use -g --quiet "github:someone/custom-tool" || exit 1' "$bin_dir/custom-tool" ||
grep -qF 'mise use -g --quiet "github:someone/custom-tool@latest" || exit 1' "$bin_dir/custom-tool" ||
fail "migration rewrites a wrapper on the pre-export template"
grep -qF 'export MISE_MINIMUM_RELEASE_AGE=0' "$bin_dir/custom-tool" ||
fail "migration brings a pre-export wrapper up to the current template"
pass "migration rewrites wrappers on the pre-export template"

grep -qF 'mise use -g --quiet "npm:some/tool" || exit 1' "$bin_dir/mise-exec-era" ||
grep -qF 'mise use -g --quiet "npm:some/tool@latest" || exit 1' "$bin_dir/mise-exec-era" ||
fail "migration rewrites a wrapper on the mise-exec template"
grep -qF 'exec mise x "npm:some/tool" -- "tool-bin" "$@"' "$bin_dir/mise-exec-era" ||
grep -qF 'exec mise x "npm:some/tool@latest" -- "tool-bin" "$@"' "$bin_dir/mise-exec-era" ||
fail "migration keeps the bin name from a mise-exec wrapper"
grep -qF 'mise use -g --quiet "aqua:some/other" || exit 1' "$bin_dir/bare-exec-era" ||
grep -qF 'mise use -g --quiet "aqua:some/other@latest" || exit 1' "$bin_dir/bare-exec-era" ||
fail "migration rewrites a wrapper on the bare-exec template"
grep -qF 'exec mise x "aqua:some/other" -- "other-bin" "$@"' "$bin_dir/bare-exec-era" ||
grep -qF 'exec mise x "aqua:some/other@latest" -- "other-bin" "$@"' "$bin_dir/bare-exec-era" ||
fail "migration keeps the bin name from a bare-exec wrapper"
pass "migration rewrites every generated form that predates --quiet"

Expand Down