-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
145 lines (129 loc) · 4 KB
/
setup
File metadata and controls
145 lines (129 loc) · 4 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env bash
# gstack setup — build browser binary + register all skills with Claude Code
set -e
GSTACK_DIR="$(cd "$(dirname "$0")" && pwd)"
SKILLS_DIR="$(dirname "$GSTACK_DIR")"
BROWSE_BIN="$GSTACK_DIR/browse/dist/browse"
FIND_BROWSE_BIN="$GSTACK_DIR/browse/dist/find-browse"
case "$(uname -s)" in
MINGW*|MSYS*|CYGWIN*)
exec powershell.exe -ExecutionPolicy Bypass -File "$GSTACK_DIR/setup.ps1"
;;
esac
resolve_compiled_binary() {
local base="$1"
if [ -x "$base" ]; then
echo "$base"
return 0
fi
if [ -x "$base.exe" ]; then
echo "$base.exe"
return 0
fi
return 1
}
ensure_windows_wrapper() {
local target="$1"
local exe="$2"
if [ ! -f "$target" ] && [ -f "$exe" ]; then
cat > "$target" <<EOF
#!/usr/bin/env bash
DIR="\$(cd "\$(dirname "\$0")" && pwd)"
exec "\$DIR/$(basename "$exe")" "\$@"
EOF
chmod +x "$target"
fi
}
ensure_runtime_wrappers() {
local browse_real
local find_real
browse_real="$(resolve_compiled_binary "$BROWSE_BIN" || true)"
find_real="$(resolve_compiled_binary "$FIND_BROWSE_BIN" || true)"
if [ -n "$browse_real" ] && [ "$browse_real" = "$BROWSE_BIN.exe" ]; then
ensure_windows_wrapper "$BROWSE_BIN" "$browse_real"
fi
if [ -n "$find_real" ] && [ "$find_real" = "$FIND_BROWSE_BIN.exe" ]; then
ensure_windows_wrapper "$FIND_BROWSE_BIN" "$find_real"
fi
}
ensure_playwright_browser() {
(
cd "$GSTACK_DIR"
bun --eval 'import { chromium } from "playwright"; const browser = await chromium.launch(); await browser.close();'
) >/dev/null 2>&1
}
# 1. Build browse binary if needed (smart rebuild: stale sources, package.json, lock)
NEEDS_BUILD=0
if [ ! -x "$BROWSE_BIN" ]; then
NEEDS_BUILD=1
elif [ -n "$(find "$GSTACK_DIR/browse/src" -type f -newer "$BROWSE_BIN" -print -quit 2>/dev/null)" ]; then
NEEDS_BUILD=1
elif [ "$GSTACK_DIR/package.json" -nt "$BROWSE_BIN" ]; then
NEEDS_BUILD=1
elif [ -f "$GSTACK_DIR/bun.lock" ] && [ "$GSTACK_DIR/bun.lock" -nt "$BROWSE_BIN" ]; then
NEEDS_BUILD=1
fi
if [ "$NEEDS_BUILD" -eq 1 ]; then
echo "Building browse binary..."
(
cd "$GSTACK_DIR"
bun install
bun run build
)
# Safety net: write .version if build script didn't (e.g., git not available during build)
if [ ! -f "$GSTACK_DIR/browse/dist/.version" ]; then
git -C "$GSTACK_DIR" rev-parse HEAD > "$GSTACK_DIR/browse/dist/.version" 2>/dev/null || true
fi
fi
ensure_runtime_wrappers
if ! resolve_compiled_binary "$BROWSE_BIN" >/dev/null 2>&1; then
echo "gstack setup failed: browse binary missing at $BROWSE_BIN" >&2
exit 1
fi
# 2. Ensure Playwright's Chromium is available
if ! ensure_playwright_browser; then
echo "Installing Playwright Chromium..."
(
cd "$GSTACK_DIR"
bunx playwright install chromium
)
fi
if ! ensure_playwright_browser; then
echo "gstack setup failed: Playwright Chromium could not be launched" >&2
exit 1
fi
# 3. Ensure ~/.gstack global state directory exists
mkdir -p "$HOME/.gstack/projects"
# 4. Only create skill symlinks if we're inside a .claude/skills directory
SKILLS_BASENAME="$(basename "$SKILLS_DIR")"
if [ "$SKILLS_BASENAME" = "skills" ]; then
linked=()
for skill_dir in "$GSTACK_DIR"/*/; do
if [ -f "$skill_dir/SKILL.md" ]; then
skill_name="$(basename "$skill_dir")"
# Skip node_modules
[ "$skill_name" = "node_modules" ] && continue
target="$SKILLS_DIR/$skill_name"
# Create or update symlink; skip if a real file/directory exists
if [ -L "$target" ] || [ ! -e "$target" ]; then
ln -snf "gstack/$skill_name" "$target"
linked+=("$skill_name")
fi
fi
done
echo "gstack ready."
echo " browse: $BROWSE_BIN"
if [ ${#linked[@]} -gt 0 ]; then
echo " linked skills: ${linked[*]}"
fi
else
echo "gstack ready."
echo " browse: $BROWSE_BIN"
echo " (skipped skill symlinks — not inside .claude/skills/)"
fi
# 4. First-time welcome + legacy cleanup
if [ ! -d "$HOME/.gstack" ]; then
mkdir -p "$HOME/.gstack"
echo " Welcome! Run /gstack-upgrade anytime to stay current."
fi
rm -f /tmp/gstack-latest-version