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
58 changes: 48 additions & 10 deletions bin/omarchy-agent-account-remove
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,19 @@ zai) name="Z.ai" ;;
*) name=${provider^} ;;
esac

copilot_missing=false
if [[ $provider == "copilot" ]] && omarchy-cmd-missing copilot; then
copilot_missing=true
fi

# Removing deletes the sign-in here. Where a CLI's logout would revoke it for
# every other copy too, its saved credential is deleted instead.
if [[ $confirm == "true" && -t 0 ]] && ! gum confirm "Forget $name? You'd have to sign in again to add it back."; then
exit 130
if [[ $confirm == "true" && -t 0 ]]; then
prompt="Forget $name? You'd have to sign in again to add it back."
if [[ $copilot_missing == "true" ]]; then
prompt="Hide $name from the Agents panel?"
fi
gum confirm "$prompt" || exit 130
fi

# 0 when the keyring holds Gemini's sign-in, 1 when it doesn't (a quiet
Expand All @@ -90,6 +99,17 @@ gemini_in_keyring() {
fi
}

remove_auth_file() {
local path=${1:-} default=$2 expand_vars=${3:-false}
if [[ -n ${path//[[:space:]]/} ]]; then
path=$(/usr/bin/python3 -c 'import os, sys; p = os.path.expanduser(sys.argv[1].strip()); print(os.path.expandvars(p) if sys.argv[2] == "true" else p)' "$path" "$expand_vars") || return 1
else
path=$default
fi
[[ -n $path ]] || return 0
rm -f -- "$path"
}

hides=true
case $provider in
claude | codex | grok)
Expand All @@ -116,15 +136,29 @@ agy)
fi
rm -f "${AGY_DIR:-$HOME/.gemini/antigravity-cli}/antigravity-oauth-token" || exit 1
;;
muse) muse logout >/dev/null || exit 1 ;;
cursor) cursor-agent logout >/dev/null || exit 1 ;;
muse)
if omarchy-cmd-present muse; then
muse logout >/dev/null || exit 1
else
remove_auth_file "${MUSE_AUTH_PATH:-}" "${XDG_CONFIG_HOME:-$HOME/.config}/muse/auth.json" true || exit 1
fi
;;
cursor)
if omarchy-cmd-present cursor-agent; then
cursor-agent logout >/dev/null || exit 1
else
remove_auth_file "${CURSOR_AUTH_PATH:-}" "${XDG_CONFIG_HOME:-$HOME/.config}/cursor/auth.json" || exit 1
fi
;;
copilot)
# Copilot signs out only from inside a session, which needs a terminal.
if [[ -t 0 ]]; then
copilot -i /logout || exit 1
else
echo "Copilot signs out from its own session: run omarchy agent account remove copilot in a terminal." >&2
exit 1
if [[ $copilot_missing == "false" ]]; then
if [[ -t 0 ]]; then
copilot -i /logout || exit 1
else
echo "Copilot signs out from its own session: run omarchy agent account remove copilot in a terminal." >&2
exit 1
fi
fi
;;
fireworks) opencode_logout fireworks-ai || exit 1 ;;
Expand All @@ -137,6 +171,10 @@ esac
# Hidden once its last sign-in is gone, so a key it still reads from the
# environment, pi, or omp doesn't bring it back. Signing in again shows it.
[[ $hides == "false" ]] || omarchy-shell omarchy.agents showAgent "$provider" false >/dev/null 2>&1
echo "Forgot $name."
if [[ $copilot_missing == "true" ]]; then
echo "Hid $name."
else
echo "Forgot $name."
fi
# The panel reads which sign-ins exist from the usage record.
omarchy-agent-usage-update --limits-only "$provider" >/dev/null 2>&1 &
2 changes: 1 addition & 1 deletion shell/plugins/agents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ per local coding model added.
provider, then saved in OpenCode, which is installed first if it's missing. Esc or the X stops the login. The browser taking focus may close the panel; the sign-in
carries on and its result arrives as a notification. Signing in to an
agent that was hidden from the panel shows it again.
- **Deleting** — Delete (or X) on a line forgets its sign-in through `omarchy agent account remove`, then hides the agent, so a key it still reads from the environment, pi, or omp doesn't bring it back. One of several Claude, Codex, or Grok accounts is only forgotten, its sessions moving to another account first when it's the one in use. Gemini's sign-in is cleared from the keyring and agy's token file, Cursor and Muse run their own logout, a key is logged out of OpenCode, and Copilot opens a terminal on its own `/logout`. An agent with no sign-in of its own is only hidden.
- **Deleting** — Delete (or X) on a line forgets its sign-in through `omarchy agent account remove`, then hides the agent, so a key it still reads from the environment, pi, or omp doesn't bring it back. One of several Claude, Codex, or Grok accounts is only forgotten, its sessions moving to another account first when it's the one in use. Gemini's sign-in is cleared from the keyring and agy's token file. Cursor and Muse run their own logout or remove the saved CLI auth file when the CLI is absent. A key is logged out of OpenCode, and Copilot opens a terminal on its own `/logout` when installed. Without its CLI, Copilot is only hidden. An agent with no sign-in of its own is only hidden.

The icon is always in the bar. On a machine with no agent yet, the panel is
the blank slate for setting one up: it opens on the same choice of agents,
Expand Down
36 changes: 36 additions & 0 deletions test/shell.d/agent-account-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,42 @@ omarchy-agent-account-remove gemini </dev/null >/dev/null
fail "removing Gemini clears agy's keyring entry and token file"
pass "removing a sign-in without accounts forgets it where its CLI keeps it"

no_cli_bin="$test_tmp/no-cli-bin"
mkdir -p "$no_cli_bin" "$test_tmp/config/cursor"
ln -s "$(type -P rm)" "$no_cli_bin/rm"
for helper in omarchy-default-agent omarchy-shell omarchy-agent-usage-update; do
ln -s "$mock_bin/$helper" "$no_cli_bin/$helper"
done
echo '{"accessToken":"tok"}' >"$test_tmp/config/cursor/auth.json"
echo '{"providers":{"meta":{"access_token":"tok"}}}' >"$HOME/muse-auth.json"
: >"$OMARCHY_TEST_BAR_LOG"
XDG_CONFIG_HOME="$test_tmp/config" CURSOR_AUTH_PATH="" PATH="$no_cli_bin:$ROOT/bin" \
omarchy-agent-account-remove --yes --agent cursor </dev/null >"$test_tmp/cursor-removed" 2>&1 ||
fail "removing Cursor works without cursor-agent installed" "$(cat "$test_tmp/cursor-removed")"
[[ ! -e $test_tmp/config/cursor/auth.json ]] && grep -qx 'omarchy.agents showAgent cursor false' "$OMARCHY_TEST_BAR_LOG" ||
fail "removing Cursor without cursor-agent deletes auth.json and hides it" "$(cat "$OMARCHY_TEST_BAR_LOG")"
MUSE_AUTH_FILE="muse-auth.json" MUSE_AUTH_PATH='~/$MUSE_AUTH_FILE' PATH="$no_cli_bin:$ROOT/bin" \
omarchy-agent-account-remove --yes --agent muse </dev/null >"$test_tmp/muse-removed" 2>&1 ||
fail "removing Muse works without muse installed" "$(cat "$test_tmp/muse-removed")"
[[ ! -e $HOME/muse-auth.json ]] && grep -qx 'omarchy.agents showAgent muse false' "$OMARCHY_TEST_BAR_LOG" ||
fail "removing Muse without muse deletes its auth file and hides it" "$(cat "$OMARCHY_TEST_BAR_LOG")"
PATH="$no_cli_bin:$ROOT/bin" \
omarchy-agent-account-remove --yes --agent copilot </dev/null >"$test_tmp/copilot-removed" 2>&1 ||
fail "removing Copilot works without copilot installed" "$(cat "$test_tmp/copilot-removed")"
grep -Fxq 'Hid Copilot.' "$test_tmp/copilot-removed" ||
fail "removing Copilot without its CLI reports that it was hidden" "$(cat "$test_tmp/copilot-removed")"
grep -qx 'omarchy.agents showAgent copilot false' "$OMARCHY_TEST_BAR_LOG" ||
fail "removing Copilot without copilot hides it" "$(cat "$OMARCHY_TEST_BAR_LOG")"
: >"$OMARCHY_TEST_BAR_LOG"
printf '#!/bin/bash\nexit 0\n' >"$no_cli_bin/copilot"
chmod +x "$no_cli_bin/copilot"
if PATH="$no_cli_bin:$ROOT/bin" omarchy-agent-account-remove --yes --agent copilot </dev/null >/dev/null 2>"$test_tmp/copilot-tty" ||
! grep -q "in a terminal" "$test_tmp/copilot-tty" ||
grep -qx 'omarchy.agents showAgent copilot false' "$OMARCHY_TEST_BAR_LOG"; then
fail "removing Copilot with copilot installed still requires a terminal" "$(cat "$test_tmp/copilot-tty")"
fi
pass "removing Cursor, Muse, or Copilot without its CLI still forgets and hides it"

: >"$notifications"
OMARCHY_TEST_LOGIN_UUID=u-events OMARCHY_TEST_LOGIN_EMAIL=events@example.com \
omarchy-agent-account-add --events claude Events </dev/null >"$test_tmp/events-output"
Expand Down