|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Set up gstack for local development — test skills from within this repo. |
| 3 | +# |
| 4 | +# Creates .config/opencode/skills/gstack → (symlink to repo root) so OpenCode |
| 5 | +# discovers skills from your working tree. Changes take effect immediately. |
| 6 | +# |
| 7 | +# Also copies .env from the main worktree if this is a Conductor workspace |
| 8 | +# or git worktree (so API keys carry over automatically). |
| 9 | +# |
| 10 | +# Usage: bin/dev-setup # set up |
| 11 | +# bin/dev-teardown # clean up |
| 12 | +set -e |
| 13 | + |
| 14 | +REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 15 | + |
| 16 | +# 1. Copy .env from main worktree (if we're a worktree and don't have one) |
| 17 | +if [ ! -f "$REPO_ROOT/.env" ]; then |
| 18 | + MAIN_WORKTREE="$(git -C "$REPO_ROOT" worktree list --porcelain 2>/dev/null | head -1 | sed 's/^worktree //')" |
| 19 | + if [ -n "$MAIN_WORKTREE" ] && [ "$MAIN_WORKTREE" != "$REPO_ROOT" ] && [ -f "$MAIN_WORKTREE/.env" ]; then |
| 20 | + cp "$MAIN_WORKTREE/.env" "$REPO_ROOT/.env" |
| 21 | + echo "Copied .env from main worktree ($MAIN_WORKTREE)" |
| 22 | + fi |
| 23 | +fi |
| 24 | + |
| 25 | +# 2. Install dependencies |
| 26 | +if [ ! -d "$REPO_ROOT/node_modules" ]; then |
| 27 | + echo "Installing dependencies..." |
| 28 | + (cd "$REPO_ROOT" && bun install) |
| 29 | +fi |
| 30 | + |
| 31 | +# 3. Create .config/opencode/skills/ inside the repo |
| 32 | +mkdir -p "$REPO_ROOT/.config/opencode/skills" |
| 33 | + |
| 34 | +# 4. Symlink .config/opencode/skills/gstack → repo root |
| 35 | +# This makes setup think it's inside a real .config/opencode/skills/ directory |
| 36 | +GSTACK_LINK="$REPO_ROOT/.config/opencode/skills/gstack" |
| 37 | +if [ -L "$GSTACK_LINK" ]; then |
| 38 | + echo "Updating existing symlink..." |
| 39 | + rm "$GSTACK_LINK" |
| 40 | +elif [ -d "$GSTACK_LINK" ]; then |
| 41 | + echo "Error: .config/opencode/skills/gstack is a real directory, not a symlink." >&2 |
| 42 | + echo "Remove it manually if you want to use dev mode." >&2 |
| 43 | + exit 1 |
| 44 | +fi |
| 45 | +ln -s "$REPO_ROOT" "$GSTACK_LINK" |
| 46 | + |
| 47 | +# 5. Create .agents/skills/gstack → repo root (for Codex/Gemini/Cursor) |
| 48 | +mkdir -p "$REPO_ROOT/.agents/skills" |
| 49 | +AGENTS_LINK="$REPO_ROOT/.agents/skills/gstack" |
| 50 | +if [ -L "$AGENTS_LINK" ]; then |
| 51 | + rm "$AGENTS_LINK" |
| 52 | +elif [ -d "$AGENTS_LINK" ]; then |
| 53 | + echo "Warning: .agents/skills/gstack is a real directory, skipping." >&2 |
| 54 | +fi |
| 55 | +if [ ! -e "$AGENTS_LINK" ]; then |
| 56 | + ln -s "$REPO_ROOT" "$AGENTS_LINK" |
| 57 | +fi |
| 58 | + |
| 59 | +# 6. Run setup via the symlink so it detects .config/opencode/skills/ as its parent |
| 60 | +"$GSTACK_LINK/setup" |
| 61 | + |
| 62 | +echo "" |
| 63 | +echo "Dev mode active. Skills resolve from this working tree." |
| 64 | +echo " .config/opencode/skills/gstack → $REPO_ROOT" |
| 65 | +echo " .agents/skills/gstack → $REPO_ROOT" |
| 66 | +echo "Edit any SKILL.md and test immediately — no copy/deploy needed." |
| 67 | +echo "" |
| 68 | +echo "To tear down: bin/dev-teardown" |
0 commit comments