* Apply agent account selection to CLI subprocesses * Fix account dispatch edge cases and remove redundant shell wrappers * Use the current account when launching a new agent session
169 lines
5.3 KiB
Bash
Executable File
169 lines
5.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# omarchy:summary=Launch the default coding agent in a terminal
|
|
# omarchy:args=[--inline] [--pick]
|
|
# omarchy:examples=omarchy agent | omarchy agent --inline
|
|
|
|
inline=false
|
|
pick=false
|
|
|
|
# Flags only. A bare prompt would shadow the subcommands under this group, so
|
|
# prompts go through omarchy-agent-prompt, which passes one here as --prompt.
|
|
while (($#)); do
|
|
case "$1" in
|
|
--inline)
|
|
inline=true
|
|
shift
|
|
;;
|
|
--pick)
|
|
pick=true
|
|
shift
|
|
;;
|
|
--prompt)
|
|
prompt=${2:?--prompt needs a value}
|
|
shift 2
|
|
;;
|
|
*)
|
|
echo "Unexpected argument: $1" >&2
|
|
echo "To pass a prompt: omarchy agent prompt \"$*\"" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Agents refuse to remember trust for $HOME, so launches from the keybinding or
|
|
# menu start in the work directory instead of re-asking on every session.
|
|
[[ $PWD == "$HOME" && -d $HOME/Work ]] && cd "$HOME/Work"
|
|
|
|
agent=$(omarchy-default-agent)
|
|
|
|
# Omarchy ships without a default, so there is nothing to launch until one is
|
|
# picked. --pick offers the choice instead of the error, which is what the
|
|
# keybinding wants: a keypress that opens nothing explains nothing.
|
|
if [[ -z $agent ]]; then
|
|
[[ $pick == "true" ]] && exec omarchy-menu summon setup.default.agent
|
|
echo "Choose default agent with: omarchy default agent <name>" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if omarchy-cmd-missing "$agent"; then
|
|
echo "$agent is not installed. Choose an installed agent with: omarchy default agent <name>" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Agents launched from the keybinding or menu run unattended, so each one starts
|
|
# with its own spelling of "don't stop to ask". Pi and Ori have none to skip.
|
|
case "$agent" in
|
|
opencode)
|
|
command=(opencode --auto)
|
|
[[ -n ${prompt:-} ]] && command+=(--prompt "$prompt")
|
|
;;
|
|
agy)
|
|
command=(agy --dangerously-skip-permissions)
|
|
[[ -n ${prompt:-} ]] && command+=(--prompt-interactive "$prompt")
|
|
;;
|
|
copilot)
|
|
command=(copilot --allow-all)
|
|
[[ -n ${prompt:-} ]] && command+=(--interactive "$prompt")
|
|
;;
|
|
crush)
|
|
# --yolo belongs to the interactive command only; `crush run` never prompts.
|
|
if [[ -n ${prompt:-} ]]; then
|
|
command=(crush run "$prompt")
|
|
else
|
|
command=(crush --yolo)
|
|
fi
|
|
;;
|
|
claude)
|
|
command=(claude --permission-mode auto)
|
|
[[ -n ${prompt:-} ]] && command+=(-- "$prompt")
|
|
;;
|
|
grok)
|
|
command=(grok --permission-mode bypassPermissions)
|
|
[[ -n ${prompt:-} ]] && command+=(-- "$prompt")
|
|
;;
|
|
openclaw)
|
|
# The launcher owns onboarding and the gateway dance: OpenClaw's terminal UI
|
|
# must attach to the running gateway (the embedded `openclaw chat` refuses to
|
|
# start while the gateway owns the state directory). It has no permission
|
|
# prompts to skip, and --message seeds the session while keeping it
|
|
# interactive.
|
|
command=(omarchy-launch-openclaw --tui)
|
|
[[ -n ${prompt:-} ]] && command+=(--message "$prompt")
|
|
;;
|
|
codex)
|
|
command=(codex --approve-for-me)
|
|
[[ -n ${prompt:-} ]] && command+=(-- "$prompt")
|
|
;;
|
|
cursor-agent)
|
|
# --yolo covers commands only; the workspace trust dialog has its own flag.
|
|
# A one-word prompt naming a subcommand (update, login, help) still runs that
|
|
# subcommand after a bare --, so the agent subcommand is named outright, and
|
|
# -- after it keeps a prompt starting with a dash from being read as an option.
|
|
command=(cursor-agent --yolo --trust)
|
|
[[ -n ${prompt:-} ]] && command+=(agent -- "$prompt")
|
|
;;
|
|
hermes)
|
|
if [[ -n ${prompt:-} ]]; then
|
|
command=(env -u HERMES_SESSION_SOURCE hermes chat --yolo --tui "--query=$prompt")
|
|
else
|
|
command=(hermes --yolo)
|
|
fi
|
|
;;
|
|
muse)
|
|
# --approval-mode never skips the tool prompts but keeps Muse's own sandbox.
|
|
command=(muse --approval-mode never)
|
|
[[ -n ${prompt:-} ]] && command+=(-- "$prompt")
|
|
;;
|
|
omp)
|
|
command=(omp --auto-approve)
|
|
[[ -n ${prompt:-} ]] && command+=(-- "$prompt")
|
|
;;
|
|
ori)
|
|
# Ori is a harness launcher, and `ori code` is the agent it runs itself.
|
|
# A prompt alone means one headless turn there, printed after the turn ends,
|
|
# so --interactive is what seeds the session with it and keeps the window.
|
|
command=(ori code)
|
|
[[ -n ${prompt:-} ]] && command+=(--interactive --prompt "$prompt")
|
|
;;
|
|
pi)
|
|
command=(pi)
|
|
[[ -n ${prompt:-} ]] && command+=("$prompt")
|
|
;;
|
|
*)
|
|
echo "Unsupported default agent: $agent" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# A new session uses the current selection rather than its parent's account
|
|
# pin. Explicit provider homes still override the selection. Carry the new pin
|
|
# in the command, since terminals launched through uwsm don't inherit our env.
|
|
case "$agent" in
|
|
claude) home_env="CLAUDE_CONFIG_DIR" ;;
|
|
codex) home_env="CODEX_HOME" ;;
|
|
grok) home_env="GROK_HOME" ;;
|
|
*) home_env="" ;;
|
|
esac
|
|
if [[ -n $home_env ]]; then
|
|
account_pin="OMARCHY_AGENT_${agent^^}_HOME"
|
|
if [[ -v $account_pin && ${!home_env:-} == "${!account_pin}" ]]; then
|
|
unset "$home_env"
|
|
fi
|
|
unset "$account_pin"
|
|
if [[ -z ${!home_env:-} ]]; then
|
|
home=$(omarchy-agent-account-home "$agent")
|
|
account_env=(env -u "$home_env" "$account_pin=$home")
|
|
[[ -n $home ]] && account_env+=("$home_env=$home")
|
|
command=("${account_env[@]}" "${command[@]}")
|
|
fi
|
|
fi
|
|
|
|
if [[ $inline == "true" ]]; then
|
|
exec "${command[@]}"
|
|
else
|
|
# A fixed app-id rather than the default org.omarchy.<binary>, so every agent
|
|
# window shares one class for window rules and themes to single out.
|
|
exec omarchy-launch-tui --app-id=org.omarchy.agent "${command[@]}"
|
|
fi
|