mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-06 13:45:35 +02:00
feat: dual-host setup + find-browse for Codex/Gemini/Cursor
- setup: add --host codex|claude|auto flag, install to ~/.codex/skills/ when targeting Codex, auto-detect installed agents - find-browse: priority chain .codex > .agents > .claude (both workspace-local and global) - dev-setup/teardown: create .agents/skills/gstack symlinks for dev mode Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
# gstack setup — build browser binary + register all skills with Claude Code
|
||||
# gstack setup — build browser binary + register skills with Claude Code / Codex
|
||||
set -e
|
||||
|
||||
GSTACK_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
SKILLS_DIR="$(dirname "$GSTACK_DIR")"
|
||||
BROWSE_BIN="$GSTACK_DIR/browse/dist/browse"
|
||||
|
||||
# ─── Parse --host flag ─────────────────────────────────────────
|
||||
HOST="claude"
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--host) HOST="$2"; shift 2 ;;
|
||||
--host=*) HOST="${1#--host=}"; shift ;;
|
||||
*) shift ;;
|
||||
esac
|
||||
done
|
||||
|
||||
case "$HOST" in
|
||||
claude|codex|auto) ;;
|
||||
*) echo "Unknown --host value: $HOST (expected claude, codex, or auto)" >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
# For auto: detect which agents are installed
|
||||
INSTALL_CLAUDE=0
|
||||
INSTALL_CODEX=0
|
||||
if [ "$HOST" = "auto" ]; then
|
||||
command -v claude >/dev/null 2>&1 && INSTALL_CLAUDE=1
|
||||
command -v codex >/dev/null 2>&1 && INSTALL_CODEX=1
|
||||
# If neither found, default to claude
|
||||
if [ "$INSTALL_CLAUDE" -eq 0 ] && [ "$INSTALL_CODEX" -eq 0 ]; then
|
||||
INSTALL_CLAUDE=1
|
||||
fi
|
||||
elif [ "$HOST" = "claude" ]; then
|
||||
INSTALL_CLAUDE=1
|
||||
elif [ "$HOST" = "codex" ]; then
|
||||
INSTALL_CODEX=1
|
||||
fi
|
||||
|
||||
ensure_playwright_browser() {
|
||||
(
|
||||
cd "$GSTACK_DIR"
|
||||
@@ -60,16 +91,17 @@ 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
|
||||
# ─── Helper: link skill subdirectories into a skills parent directory ──
|
||||
link_skill_dirs() {
|
||||
local gstack_dir="$1"
|
||||
local skills_dir="$2"
|
||||
local 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"
|
||||
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"
|
||||
@@ -77,19 +109,75 @@ if [ "$SKILLS_BASENAME" = "skills" ]; then
|
||||
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/)"
|
||||
}
|
||||
|
||||
# ─── Helper: create .agents/skills/gstack/ sidecar symlinks ──────────
|
||||
# Codex/Gemini/Cursor read skills from .agents/skills/. We link runtime
|
||||
# assets (bin/, browse/dist/, review/, qa/, etc.) so skill templates can
|
||||
# resolve paths like $SKILL_ROOT/review/design-checklist.md.
|
||||
create_agents_sidecar() {
|
||||
local repo_root="$1"
|
||||
local agents_gstack="$repo_root/.agents/skills/gstack"
|
||||
mkdir -p "$agents_gstack"
|
||||
|
||||
# Sidecar directories that skills reference at runtime
|
||||
for asset in bin browse review qa; do
|
||||
local src="$GSTACK_DIR/$asset"
|
||||
local dst="$agents_gstack/$asset"
|
||||
if [ -d "$src" ] || [ -f "$src" ]; then
|
||||
if [ -L "$dst" ] || [ ! -e "$dst" ]; then
|
||||
ln -snf "$src" "$dst"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# 4. Install for Claude (default)
|
||||
SKILLS_BASENAME="$(basename "$SKILLS_DIR")"
|
||||
if [ "$INSTALL_CLAUDE" -eq 1 ]; then
|
||||
if [ "$SKILLS_BASENAME" = "skills" ]; then
|
||||
link_skill_dirs "$GSTACK_DIR" "$SKILLS_DIR"
|
||||
echo "gstack ready (claude)."
|
||||
echo " browse: $BROWSE_BIN"
|
||||
else
|
||||
echo "gstack ready (claude)."
|
||||
echo " browse: $BROWSE_BIN"
|
||||
echo " (skipped skill symlinks — not inside .claude/skills/)"
|
||||
fi
|
||||
fi
|
||||
|
||||
# 4. First-time welcome + legacy cleanup
|
||||
# 5. Install for Codex
|
||||
if [ "$INSTALL_CODEX" -eq 1 ]; then
|
||||
CODEX_SKILLS="$HOME/.codex/skills"
|
||||
CODEX_GSTACK="$CODEX_SKILLS/gstack"
|
||||
mkdir -p "$CODEX_SKILLS"
|
||||
|
||||
# Symlink or copy gstack into ~/.codex/skills/gstack
|
||||
if [ -L "$CODEX_GSTACK" ] || [ ! -e "$CODEX_GSTACK" ]; then
|
||||
ln -snf "$GSTACK_DIR" "$CODEX_GSTACK"
|
||||
fi
|
||||
link_skill_dirs "$GSTACK_DIR" "$CODEX_SKILLS"
|
||||
|
||||
echo "gstack ready (codex)."
|
||||
echo " browse: $BROWSE_BIN"
|
||||
echo " codex skills: $CODEX_SKILLS"
|
||||
fi
|
||||
|
||||
# 6. Create .agents/ sidecar symlinks (useful for Codex/Gemini/Cursor workspace-local)
|
||||
if [ "$INSTALL_CODEX" -eq 1 ]; then
|
||||
# Detect repo root: if we're inside a skills directory, go up two levels
|
||||
if [ "$SKILLS_BASENAME" = "skills" ]; then
|
||||
REPO_ROOT="$(dirname "$SKILLS_DIR")"
|
||||
else
|
||||
REPO_ROOT="$GSTACK_DIR"
|
||||
fi
|
||||
create_agents_sidecar "$REPO_ROOT"
|
||||
fi
|
||||
|
||||
# 7. First-time welcome + legacy cleanup
|
||||
if [ ! -d "$HOME/.gstack" ]; then
|
||||
mkdir -p "$HOME/.gstack"
|
||||
echo " Welcome! Run /gstack-upgrade anytime to stay current."
|
||||
|
||||
Reference in New Issue
Block a user