-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent-stack.plugin.zsh
More file actions
128 lines (108 loc) · 3.02 KB
/
Copy pathagent-stack.plugin.zsh
File metadata and controls
128 lines (108 loc) · 3.02 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
_agent_stack_home() {
echo "${HOME}/.agent-stack"
}
_agent_env_lines() {
local stack_home
stack_home=$(_agent_stack_home)
local env_file=${stack_home}/.env
if [[ ! -f "$env_file" ]]; then
return 0
fi
if command -v op &>/dev/null; then
op inject -i "$env_file"
else
cat "$env_file"
fi
}
_agent_env_value() {
local key=$1
while IFS= read -r line; do
[[ -z "$line" || "$line" == \#* ]] && continue
if [[ "$line" == "${key}="* ]]; then
echo "${line#*=}"
return 0
fi
done < <(_agent_env_lines)
}
_agent_ensure_home() {
local stack_home
stack_home=$(_agent_stack_home)
mkdir -p "${stack_home}/.claude" "${stack_home}/.codex" "${stack_home}/.chrome-agent"
if [[ ! -f "${stack_home}/.env" ]]; then
touch "${stack_home}/.env"
fi
}
_agent_chrome() {
local stack_home
stack_home=$(_agent_stack_home)
local chrome_bin="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
local chrome_port
_agent_ensure_home
if [[ "$OSTYPE" != darwin* ]]; then
echo "agent chrome currently supports macOS only" >&2
return 1
fi
if [[ ! -x "$chrome_bin" ]]; then
echo "Google Chrome not found at ${chrome_bin}" >&2
return 1
fi
chrome_port=$(_agent_env_value CHROME_REMOTE_PORT)
if [[ -z "$chrome_port" ]]; then
chrome_port=9222
fi
"$chrome_bin" \
--remote-debugging-port="${chrome_port}" \
--remote-debugging-address=0.0.0.0 \
--user-data-dir="${stack_home}/.chrome-agent" \
--no-first-run \
--no-default-browser-check \
--password-store=basic \
--disable-blink-features=AutomationControlled
}
_agent_run() {
local stack_home
stack_home=$(_agent_stack_home)
local env_file=${stack_home}/.env
local env_args=()
_agent_ensure_home
if [[ -f "$env_file" ]]; then
if command -v op &>/dev/null; then
while IFS= read -r line; do
[[ -n "$line" && "$line" != \#* ]] && env_args+=(-e "$line")
done < <(op inject -i "$env_file")
else
env_args=(--env-file "$env_file")
fi
fi
docker run -it \
-v "$(pwd)":/workspace \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "${HOME}/.gitconfig:/home/agent/.gitconfig:ro" \
-v "${stack_home}:/home/agent/.agent-stack" \
-v agent-mise-data:/home/agent/.local/share/mise \
${env_args[@]} \
-e CODEX_HOME=/home/agent/.agent-stack/.codex \
-e CLAUDE_CONFIG_DIR=/home/agent/.agent-stack/.claude \
--add-host host.docker.internal:host-gateway \
ghcr.io/syati/agent-stack:latest zsh
}
_agent_update() {
docker pull ghcr.io/syati/agent-stack:latest
}
_agent_help() {
echo "Usage: agent [command]"
echo ""
echo "Commands:"
echo " (none) Start agent container in current directory"
echo " chrome Start host Chrome with remote debugging for agent-browser"
echo " update Pull latest image from ghcr.io"
echo " help Show this help"
}
agent() {
case "$1" in
chrome) _agent_chrome ;;
update) _agent_update ;;
help|--help|-h) _agent_help ;;
*) _agent_run ;;
esac
}