Show agent installation progress in a terminal

This commit is contained in:
David Heinemeier Hansson
2026-08-04 07:45:36 -07:00
parent 2324851da1
commit a7cc924a10
2 changed files with 57 additions and 26 deletions
+13 -7
View File
@@ -4,7 +4,13 @@
# omarchy:args=[pi|omp|opencode|claude|codex|grok|gemini|copilot|crush] # omarchy:args=[pi|omp|opencode|claude|codex|grok|gemini|copilot|crush]
# omarchy:examples=omarchy default agent | omarchy default agent codex | omarchy default agent claude # omarchy:examples=omarchy default agent | omarchy default agent codex | omarchy default agent claude
agent_file="$HOME/.local/state/omarchy/defaults/agent" installing=false
if [[ ${1:-} == "--install" ]]; then
installing=true
shift
fi
agent_file="$HOME/.config/omarchy/defaults/agent"
if (($# == 0)); then if (($# == 0)); then
if [[ -f $agent_file ]]; then if [[ -f $agent_file ]]; then
@@ -32,16 +38,14 @@ copilot | github-copilot) agent="copilot"; name="GitHub Copilot" ;;
esac esac
agent_package=${agent_package:-$agent} agent_package=${agent_package:-$agent}
installing=false
if ! mise where "$agent_package" &>/dev/null; then if [[ $installing == "false" ]] && ! mise where "$agent_package" &>/dev/null; then
installing=true exec omarchy-launch-floating-terminal-with-presentation omarchy-default-agent --install "$agent"
omarchy-notification-send -g 󰚩 "Installing $name with mise" "This might take a few minutes..."
fi fi
if ! mise use -g "$agent_package"; then if ! mise use -g "$agent_package"; then
if [[ $installing == "true" ]]; then if [[ $installing == "true" ]]; then
omarchy-notification-send -g 󰚩 "Could not install $name with mise" echo "Could not install $name with mise" >&2
else else
omarchy-notification-send -g 󰚩 "Could not set $name as the default coding agent" omarchy-notification-send -g 󰚩 "Could not set $name as the default coding agent"
fi fi
@@ -51,4 +55,6 @@ fi
mkdir -p "$(dirname "$agent_file")" mkdir -p "$(dirname "$agent_file")"
printf '%s\n' "$agent" >"$agent_file" printf '%s\n' "$agent" >"$agent_file"
omarchy-notification-send -g 󰚩 "$name is now the default coding agent" if [[ $installing == "false" ]]; then
omarchy-notification-send -g 󰚩 "$name is now the default coding agent"
fi
+44 -19
View File
@@ -9,6 +9,7 @@ trap 'rm -rf "$test_tmp"' EXIT
mock_bin="$test_tmp/bin" mock_bin="$test_tmp/bin"
test_home="$test_tmp/home" test_home="$test_tmp/home"
agent_file="$test_home/.config/omarchy/defaults/agent"
notification_log="$test_tmp/notifications" notification_log="$test_tmp/notifications"
notification_history="$test_tmp/notification-history" notification_history="$test_tmp/notification-history"
launch_log="$test_tmp/launch" launch_log="$test_tmp/launch"
@@ -16,6 +17,7 @@ inline_log="$test_tmp/inline"
mise_log="$test_tmp/mise" mise_log="$test_tmp/mise"
mise_history="$test_tmp/mise-history" mise_history="$test_tmp/mise-history"
stub_log="$test_tmp/stubs" stub_log="$test_tmp/stubs"
terminal_log="$test_tmp/terminal"
mkdir -p "$mock_bin" "$test_home" mkdir -p "$mock_bin" "$test_home"
cat >"$mock_bin/omarchy-notification-send" <<'SH' cat >"$mock_bin/omarchy-notification-send" <<'SH'
@@ -34,6 +36,11 @@ cat >"$mock_bin/omarchy-launch-tui" <<'SH'
printf '%s\0' "$@" >"$OMARCHY_TEST_AGENT_LAUNCH_LOG" printf '%s\0' "$@" >"$OMARCHY_TEST_AGENT_LAUNCH_LOG"
SH SH
cat >"$mock_bin/omarchy-launch-floating-terminal-with-presentation" <<'SH'
#!/bin/bash
printf '%s\0' "$@" >"$OMARCHY_TEST_AGENT_TERMINAL_LOG"
SH
cat >"$mock_bin/opencode" <<'SH' cat >"$mock_bin/opencode" <<'SH'
#!/bin/bash #!/bin/bash
printf '%s\0' opencode "$@" >"$OMARCHY_TEST_AGENT_INLINE_LOG" printf '%s\0' opencode "$@" >"$OMARCHY_TEST_AGENT_INLINE_LOG"
@@ -77,6 +84,7 @@ export OMARCHY_TEST_AGENT_INLINE_LOG="$inline_log"
export OMARCHY_TEST_MISE_LOG="$mise_log" export OMARCHY_TEST_MISE_LOG="$mise_log"
export OMARCHY_TEST_MISE_HISTORY="$mise_history" export OMARCHY_TEST_MISE_HISTORY="$mise_history"
export OMARCHY_TEST_STUB_LOG="$stub_log" export OMARCHY_TEST_STUB_LOG="$stub_log"
export OMARCHY_TEST_AGENT_TERMINAL_LOG="$terminal_log"
grok_package="npm:@xai-official/grok" grok_package="npm:@xai-official/grok"
omp_package="github:can1357/oh-my-pi" omp_package="github:can1357/oh-my-pi"
@@ -183,7 +191,7 @@ declare -A expected_packages=(
for selection in "${!expected_agents[@]}"; do for selection in "${!expected_agents[@]}"; do
expected=${expected_agents[$selection]} expected=${expected_agents[$selection]}
omarchy-default-agent "$selection" OMARCHY_TEST_AGENT_INSTALLED=true omarchy-default-agent "$selection"
[[ $(omarchy-default-agent) == $expected ]] || fail "default agent canonicalizes $selection" [[ $(omarchy-default-agent) == $expected ]] || fail "default agent canonicalizes $selection"
mapfile -d '' -t mise_args <"$mise_log" mapfile -d '' -t mise_args <"$mise_log"
@@ -191,26 +199,42 @@ for selection in "${!expected_agents[@]}"; do
fail "default agent installs $selection globally through mise" fail "default agent installs $selection globally through mise"
done done
pass "default agent installs and accepts every supported provider and alias" pass "default agent installs and accepts every supported provider and alias"
[[ -f $agent_file && ! -e $test_home/.local/state/omarchy/defaults/agent ]] ||
fail "default agent stores its selection in Omarchy user config"
pass "default agent stores its selection in Omarchy user config"
OMARCHY_TEST_AGENT_INSTALLED=true omarchy-default-agent pi
: >"$notification_history"
: >"$terminal_log"
omarchy-default-agent github-copilot
mapfile -d '' -t terminal_args <"$terminal_log"
[[ ${terminal_args[0]} == "omarchy-default-agent" && ${terminal_args[1]} == "--install" && ${terminal_args[2]} == "copilot" ]] ||
fail "missing agent installation opens in a terminal"
[[ ! -s $notification_history ]] || fail "missing agent installation skips notifications"
[[ $(omarchy-default-agent) == "pi" ]] || fail "missing agent installation waits to change the selection"
omarchy-default-agent --install github-copilot
mapfile -d '' -t mise_args <"$mise_log"
[[ ${mise_args[0]} == "use" && ${mise_args[1]} == "-g" && ${mise_args[2]} == "copilot" ]] ||
fail "visible agent installation activates the provider globally through mise"
[[ $(omarchy-default-agent) == "copilot" ]] || fail "visible agent installation changes the selection after mise succeeds"
[[ ! -s $notification_history ]] || fail "visible agent installation leaves progress to the terminal"
pass "missing agents install visibly without notifications"
: >"$notification_history" : >"$notification_history"
omarchy-default-agent github-copilot : >"$terminal_log"
OMARCHY_TEST_AGENT_INSTALLED=true omarchy-default-agent github-copilot
[[ ! -s $terminal_log ]] || fail "installed agent selection skips the terminal"
mapfile -d '' -t notification_args <"$notification_log" mapfile -d '' -t notification_args <"$notification_log"
[[ ${notification_args[0]} == "-g" && ${notification_args[2]} == "GitHub Copilot is now the default coding agent" ]] || [[ ${notification_args[0]} == "-g" && ${notification_args[2]} == "GitHub Copilot is now the default coding agent" ]] ||
fail "default agent sends a selection notification" fail "default agent sends a selection notification"
mapfile -d '' -t notification_history_args <"$notification_history" mapfile -d '' -t notification_history_args <"$notification_history"
[[ ${notification_history_args[2]} == "Installing GitHub Copilot with mise" && ${notification_history_args[3]} == "This might take a few minutes..." ]] ||
fail "default agent describes how long installation might take"
pass "default agent sends installation and selection notifications"
: >"$notification_history"
OMARCHY_TEST_AGENT_INSTALLED=true omarchy-default-agent github-copilot
mapfile -d '' -t notification_history_args <"$notification_history"
[[ ${#notification_history_args[@]} == 3 && ${notification_history_args[2]} == "GitHub Copilot is now the default coding agent" ]] || [[ ${#notification_history_args[@]} == 3 && ${notification_history_args[2]} == "GitHub Copilot is now the default coding agent" ]] ||
fail "default agent skips installation notifications when the provider is already installed" fail "installed agent selection sends only the completion notification"
mapfile -d '' -t mise_args <"$mise_log" mapfile -d '' -t mise_args <"$mise_log"
[[ ${mise_args[0]} == "use" && ${mise_args[1]} == "-g" && ${mise_args[2]} == "copilot" ]] || [[ ${mise_args[0]} == "use" && ${mise_args[1]} == "-g" && ${mise_args[2]} == "copilot" ]] ||
fail "default agent still activates an installed provider globally through mise" fail "default agent still activates an installed provider globally through mise"
pass "default agent only sends installation notifications for missing providers" pass "installed agents select immediately with a notification"
if omarchy-default-agent unsupported >"$test_tmp/invalid-output" 2>&1; then if omarchy-default-agent unsupported >"$test_tmp/invalid-output" 2>&1; then
fail "default agent rejects unsupported providers" fail "default agent rejects unsupported providers"
@@ -220,13 +244,14 @@ grep -F "Usage: omarchy-default-agent" "$test_tmp/invalid-output" >/dev/null ||
[[ $(omarchy-default-agent) == "copilot" ]] || fail "invalid selection preserves the current default agent" [[ $(omarchy-default-agent) == "copilot" ]] || fail "invalid selection preserves the current default agent"
pass "default agent rejects unsupported providers without changing the selection" pass "default agent rejects unsupported providers without changing the selection"
if OMARCHY_TEST_MISE_FAIL=true omarchy-default-agent codex >"$test_tmp/install-failure-output" 2>&1; then : >"$notification_history"
if OMARCHY_TEST_MISE_FAIL=true omarchy-default-agent --install codex >"$test_tmp/install-failure-output" 2>&1; then
fail "default agent rejects a failed mise installation" fail "default agent rejects a failed mise installation"
fi fi
[[ $(omarchy-default-agent) == "copilot" ]] || fail "failed installation preserves the current default agent" [[ $(omarchy-default-agent) == "copilot" ]] || fail "failed installation preserves the current default agent"
mapfile -d '' -t notification_args <"$notification_log" grep -F "Could not install Codex with mise" "$test_tmp/install-failure-output" >/dev/null ||
[[ ${notification_args[2]} == "Could not install Codex with mise" ]] || fail "default agent reports a failed mise installation in the terminal"
fail "default agent reports a failed mise installation" [[ ! -s $notification_history ]] || fail "failed visible agent installation skips notifications"
pass "default agent changes selection only after mise installs the provider" pass "default agent changes selection only after mise installs the provider"
: >"$notification_history" : >"$notification_history"
@@ -247,7 +272,7 @@ assert_launch() {
shift shift
local expected=("$@") local expected=("$@")
printf '%s\n' "$agent" >"$test_home/.local/state/omarchy/defaults/agent" printf '%s\n' "$agent" >"$agent_file"
omarchy-launch-agent "Review this" project omarchy-launch-agent "Review this" project
mapfile -d '' -t actual <"$launch_log" mapfile -d '' -t actual <"$launch_log"
@@ -274,14 +299,14 @@ pass "agent launcher adapts initial prompts for every supported agent"
mkdir -p "$test_home/.local/bin" mkdir -p "$test_home/.local/bin"
touch "$test_home/.local/bin/gemini" touch "$test_home/.local/bin/gemini"
chmod +x "$test_home/.local/bin/gemini" chmod +x "$test_home/.local/bin/gemini"
printf '%s\n' "gemini" >"$test_home/.local/state/omarchy/defaults/agent" printf '%s\n' "gemini" >"$agent_file"
OMARCHY_TEST_MISSING_COMMAND=gemini omarchy-launch-agent "Review this project" OMARCHY_TEST_MISSING_COMMAND=gemini omarchy-launch-agent "Review this project"
mapfile -d '' -t launch_args <"$launch_log" mapfile -d '' -t launch_args <"$launch_log"
[[ ${launch_args[0]} == "gemini" && ${launch_args[1]} == "--prompt-interactive" ]] || [[ ${launch_args[0]} == "gemini" && ${launch_args[1]} == "--prompt-interactive" ]] ||
fail "agent launcher finds a lazy wrapper outside the session PATH" fail "agent launcher finds a lazy wrapper outside the session PATH"
pass "agent launcher finds lazy wrappers outside the session PATH" pass "agent launcher finds lazy wrappers outside the session PATH"
printf '%s\n' "opencode" >"$test_home/.local/state/omarchy/defaults/agent" printf '%s\n' "opencode" >"$agent_file"
omarchy-launch-agent omarchy-launch-agent
mapfile -d '' -t launch_args <"$launch_log" mapfile -d '' -t launch_args <"$launch_log"
[[ ${#launch_args[@]} == 1 && ${launch_args[0]} == "opencode" ]] || [[ ${#launch_args[@]} == 1 && ${launch_args[0]} == "opencode" ]] ||
@@ -294,7 +319,7 @@ mapfile -d '' -t inline_args <"$inline_log"
fail "inline agent launcher runs in the current terminal" fail "inline agent launcher runs in the current terminal"
pass "inline agent launcher runs in the current terminal" pass "inline agent launcher runs in the current terminal"
printf '%s\n' "missing" >"$test_home/.local/state/omarchy/defaults/agent" printf '%s\n' "missing" >"$agent_file"
if OMARCHY_TEST_MISSING_COMMAND=missing omarchy-launch-agent >"$test_tmp/missing-output" 2>&1; then if OMARCHY_TEST_MISSING_COMMAND=missing omarchy-launch-agent >"$test_tmp/missing-output" 2>&1; then
fail "agent launcher rejects a missing default command" fail "agent launcher rejects a missing default command"
fi fi