-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathbux-agent-shell
More file actions
executable file
·45 lines (41 loc) · 1.74 KB
/
Copy pathbux-agent-shell
File metadata and controls
executable file
·45 lines (41 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bash
# Launch the agent the box is actually configured for in the web terminal /
# SSH session, instead of hardcoding claude (ENG-4785).
#
# Picks codex when the box is on the free DeepSeek path (the browser-use-free
# profile is the default in ~/.codex/config.toml) or when codex is signed in;
# otherwise falls back to claude. Mirrors the agent-selection logic the
# telegram bot uses so the terminal and the bot agree on which agent runs.
set -u
CODEX_CONFIG="${CODEX_CONFIG:-$HOME/.codex/config.toml}"
# True if the top-level `profile` key selects the free DeepSeek profile.
# Top-level only: stop scanning at the first [table] header. Exact key match.
free_profile_active() {
[ -f "$CODEX_CONFIG" ] || return 1
while IFS= read -r line; do
# Strip leading whitespace so indented headers/keys are matched uniformly.
trimmed="${line#"${line%%[![:space:]]*}"}"
# Extract the key (text before the first '='), whitespace-trimmed, so we
# match the EXACT top-level `profile` key — not `profile_dir`/`profiles`.
key="${trimmed%%=*}"
key="${key%"${key##*[![:space:]]}"}"
case "$trimmed" in
\[*) return 1 ;; # first table header -> no top-level profile line
esac
if [ "$key" = "profile" ] && [ "$trimmed" != "$key" ]; then
val="${trimmed#*=}"
val="$(printf '%s' "$val" | tr -d ' "'\''')"
[ "$val" = "browser-use-free" ] && return 0 || return 1
fi
done < "$CODEX_CONFIG"
return 1
}
codex_signed_in() {
command -v codex >/dev/null 2>&1 || return 1
codex login status 2>&1 | grep -qi "logged in" && \
! (codex login status 2>&1 | grep -qi "not logged in")
}
if command -v codex >/dev/null 2>&1 && { free_profile_active || codex_signed_in; }; then
exec codex "$@"
fi
exec claude "$@"