mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-01 19:25:10 +02:00
1e06b6a5c6
* feat: add {{BASE_BRANCH_DETECT}} resolver to gen-skill-docs
DRY placeholder for dynamic base branch detection across PR-targeting
skills. Detects via gh pr view (existing PR base) → gh repo view
(repo default) → fallback to main.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: ship skill detects base branch instead of hardcoding main
Replaces ~14 hardcoded 'main' references with dynamic detection via
{{BASE_BRANCH_DETECT}}. Fixes stacked branches and Conductor workspaces
targeting non-main branches. Adds --base <base> to gh pr create.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: review, qa, plan-ceo-review detect base branch dynamically
Same pattern as ship: replaces hardcoded 'main' with {{BASE_BRANCH_DETECT}}.
Also cleans up qa bash-isms (REPORT_DIR variable, port chaining).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: retro detects default branch instead of hardcoding origin/main
Retro queries commit history (not PR targets), so uses simpler detection:
gh repo view defaultBranchRef. Replaces ~11 origin/main refs with
origin/<default>.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs: add explicit cross-step references in gstack-upgrade template
Bash blocks are self-contained, but cross-block variable references
(INSTALL_DIR from Step 2) were implicit. Adds prose making them explicit.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs+test: SKILL authoring guidance + regression tests
Adds "Writing SKILL templates" section to CLAUDE.md explaining that
templates are prompts, not scripts. Adds validation test catching
hardcoded 'main' in git commands, and resolver content test.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs: update ARCHITECTURE + CONTRIBUTING for new placeholders
Add {{BASE_BRANCH_DETECT}} to ARCHITECTURE.md placeholder list.
Cross-reference CLAUDE.md template authoring guidance from CONTRIBUTING.md.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* chore: bump version and changelog (v0.3.10)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: add missing blank line between resolver functions
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* test: add 3 E2E smoke tests for base branch detection
- /review: verifies Step 0 detection + git diff against detected base
- /ship: truncated dry-run (Steps 0-1 only, no push/PR), asserts no
destructive actions
- /retro: verifies default branch detection for git log queries
Covers the {{BASE_BRANCH_DETECT}} resolver path (review), the ship
template's dual abort check, and retro's inline detection pattern.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* chore: bump version and changelog (v0.4.2)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
191 lines
6.2 KiB
Cheetah
191 lines
6.2 KiB
Cheetah
---
|
|
name: gstack-upgrade
|
|
version: 1.1.0
|
|
description: |
|
|
Upgrade gstack to the latest version. Detects global vs vendored install,
|
|
runs the upgrade, and shows what's new.
|
|
allowed-tools:
|
|
- Bash
|
|
- Read
|
|
- Write
|
|
- AskUserQuestion
|
|
---
|
|
|
|
# /gstack-upgrade
|
|
|
|
Upgrade gstack to the latest version and show what's new.
|
|
|
|
## Inline upgrade flow
|
|
|
|
This section is referenced by all skill preambles when they detect `UPGRADE_AVAILABLE`.
|
|
|
|
### Step 1: Ask the user (or auto-upgrade)
|
|
|
|
First, check if auto-upgrade is enabled:
|
|
```bash
|
|
_AUTO=""
|
|
[ "${GSTACK_AUTO_UPGRADE:-}" = "1" ] && _AUTO="true"
|
|
[ -z "$_AUTO" ] && _AUTO=$(~/.claude/skills/gstack/bin/gstack-config get auto_upgrade 2>/dev/null || true)
|
|
echo "AUTO_UPGRADE=$_AUTO"
|
|
```
|
|
|
|
**If `AUTO_UPGRADE=true` or `AUTO_UPGRADE=1`:** Skip AskUserQuestion. Log "Auto-upgrading gstack v{old} → v{new}..." and proceed directly to Step 2. If `./setup` fails during auto-upgrade, restore from backup (`.bak` directory) and warn the user: "Auto-upgrade failed — restored previous version. Run `/gstack-upgrade` manually to retry."
|
|
|
|
**Otherwise**, use AskUserQuestion:
|
|
- Question: "gstack **v{new}** is available (you're on v{old}). Upgrade now?"
|
|
- Options: ["Yes, upgrade now", "Always keep me up to date", "Not now", "Never ask again"]
|
|
|
|
**If "Yes, upgrade now":** Proceed to Step 2.
|
|
|
|
**If "Always keep me up to date":**
|
|
```bash
|
|
~/.claude/skills/gstack/bin/gstack-config set auto_upgrade true
|
|
```
|
|
Tell user: "Auto-upgrade enabled. Future updates will install automatically." Then proceed to Step 2.
|
|
|
|
**If "Not now":** Write snooze state with escalating backoff (first snooze = 24h, second = 48h, third+ = 1 week), then continue with the current skill. Do not mention the upgrade again.
|
|
```bash
|
|
_SNOOZE_FILE=~/.gstack/update-snoozed
|
|
_REMOTE_VER="{new}"
|
|
_CUR_LEVEL=0
|
|
if [ -f "$_SNOOZE_FILE" ]; then
|
|
_SNOOZED_VER=$(awk '{print $1}' "$_SNOOZE_FILE")
|
|
if [ "$_SNOOZED_VER" = "$_REMOTE_VER" ]; then
|
|
_CUR_LEVEL=$(awk '{print $2}' "$_SNOOZE_FILE")
|
|
case "$_CUR_LEVEL" in *[!0-9]*) _CUR_LEVEL=0 ;; esac
|
|
fi
|
|
fi
|
|
_NEW_LEVEL=$((_CUR_LEVEL + 1))
|
|
[ "$_NEW_LEVEL" -gt 3 ] && _NEW_LEVEL=3
|
|
echo "$_REMOTE_VER $_NEW_LEVEL $(date +%s)" > "$_SNOOZE_FILE"
|
|
```
|
|
Note: `{new}` is the remote version from the `UPGRADE_AVAILABLE` output — substitute it from the update check result.
|
|
|
|
Tell user the snooze duration: "Next reminder in 24h" (or 48h or 1 week, depending on level). Tip: "Set `auto_upgrade: true` in `~/.gstack/config.yaml` for automatic upgrades."
|
|
|
|
**If "Never ask again":**
|
|
```bash
|
|
~/.claude/skills/gstack/bin/gstack-config set update_check false
|
|
```
|
|
Tell user: "Update checks disabled. Run `~/.claude/skills/gstack/bin/gstack-config set update_check true` to re-enable."
|
|
Continue with the current skill.
|
|
|
|
### Step 2: Detect install type
|
|
|
|
```bash
|
|
if [ -d "$HOME/.claude/skills/gstack/.git" ]; then
|
|
INSTALL_TYPE="global-git"
|
|
INSTALL_DIR="$HOME/.claude/skills/gstack"
|
|
elif [ -d ".claude/skills/gstack/.git" ]; then
|
|
INSTALL_TYPE="local-git"
|
|
INSTALL_DIR=".claude/skills/gstack"
|
|
elif [ -d ".claude/skills/gstack" ]; then
|
|
INSTALL_TYPE="vendored"
|
|
INSTALL_DIR=".claude/skills/gstack"
|
|
elif [ -d "$HOME/.claude/skills/gstack" ]; then
|
|
INSTALL_TYPE="vendored-global"
|
|
INSTALL_DIR="$HOME/.claude/skills/gstack"
|
|
else
|
|
echo "ERROR: gstack not found"
|
|
exit 1
|
|
fi
|
|
echo "Install type: $INSTALL_TYPE at $INSTALL_DIR"
|
|
```
|
|
|
|
The install type and directory path printed above will be used in all subsequent steps.
|
|
|
|
### Step 3: Save old version
|
|
|
|
Use the install directory from Step 2's output below:
|
|
|
|
```bash
|
|
OLD_VERSION=$(cat "$INSTALL_DIR/VERSION" 2>/dev/null || echo "unknown")
|
|
```
|
|
|
|
### Step 4: Upgrade
|
|
|
|
Use the install type and directory detected in Step 2:
|
|
|
|
**For git installs** (global-git, local-git):
|
|
```bash
|
|
cd "$INSTALL_DIR"
|
|
STASH_OUTPUT=$(git stash 2>&1)
|
|
git fetch origin
|
|
git reset --hard origin/main
|
|
./setup
|
|
```
|
|
If `$STASH_OUTPUT` contains "Saved working directory", warn the user: "Note: local changes were stashed. Run `git stash pop` in the skill directory to restore them."
|
|
|
|
**For vendored installs** (vendored, vendored-global):
|
|
```bash
|
|
PARENT=$(dirname "$INSTALL_DIR")
|
|
TMP_DIR=$(mktemp -d)
|
|
git clone --depth 1 https://github.com/garrytan/gstack.git "$TMP_DIR/gstack"
|
|
mv "$INSTALL_DIR" "$INSTALL_DIR.bak"
|
|
mv "$TMP_DIR/gstack" "$INSTALL_DIR"
|
|
cd "$INSTALL_DIR" && ./setup
|
|
rm -rf "$INSTALL_DIR.bak" "$TMP_DIR"
|
|
```
|
|
|
|
### Step 4.5: Sync local vendored copy
|
|
|
|
Use the install directory from Step 2. Check if there's also a local vendored copy that needs updating:
|
|
|
|
```bash
|
|
_ROOT=$(git rev-parse --show-toplevel 2>/dev/null)
|
|
LOCAL_GSTACK=""
|
|
if [ -n "$_ROOT" ] && [ -d "$_ROOT/.claude/skills/gstack" ]; then
|
|
_RESOLVED_LOCAL=$(cd "$_ROOT/.claude/skills/gstack" && pwd -P)
|
|
_RESOLVED_PRIMARY=$(cd "$INSTALL_DIR" && pwd -P)
|
|
if [ "$_RESOLVED_LOCAL" != "$_RESOLVED_PRIMARY" ]; then
|
|
LOCAL_GSTACK="$_ROOT/.claude/skills/gstack"
|
|
fi
|
|
fi
|
|
echo "LOCAL_GSTACK=$LOCAL_GSTACK"
|
|
```
|
|
|
|
If `LOCAL_GSTACK` is non-empty, update it by copying from the freshly-upgraded primary install (same approach as README vendored install):
|
|
```bash
|
|
mv "$LOCAL_GSTACK" "$LOCAL_GSTACK.bak"
|
|
cp -Rf "$INSTALL_DIR" "$LOCAL_GSTACK"
|
|
rm -rf "$LOCAL_GSTACK/.git"
|
|
cd "$LOCAL_GSTACK" && ./setup
|
|
rm -rf "$LOCAL_GSTACK.bak"
|
|
```
|
|
Tell user: "Also updated vendored copy at `$LOCAL_GSTACK` — commit `.claude/skills/gstack/` when you're ready."
|
|
|
|
### Step 5: Write marker + clear cache
|
|
|
|
```bash
|
|
mkdir -p ~/.gstack
|
|
echo "$OLD_VERSION" > ~/.gstack/just-upgraded-from
|
|
rm -f ~/.gstack/last-update-check
|
|
rm -f ~/.gstack/update-snoozed
|
|
```
|
|
|
|
### Step 6: Show What's New
|
|
|
|
Read `$INSTALL_DIR/CHANGELOG.md`. Find all version entries between the old version and the new version. Summarize as 5-7 bullets grouped by theme. Don't overwhelm — focus on user-facing changes. Skip internal refactors unless they're significant.
|
|
|
|
Format:
|
|
```
|
|
gstack v{new} — upgraded from v{old}!
|
|
|
|
What's new:
|
|
- [bullet 1]
|
|
- [bullet 2]
|
|
- ...
|
|
|
|
Happy shipping!
|
|
```
|
|
|
|
### Step 7: Continue
|
|
|
|
After showing What's New, continue with whatever skill the user originally invoked. The upgrade is done — no further action needed.
|
|
|
|
---
|
|
|
|
## Standalone usage
|
|
|
|
When invoked directly as `/gstack-upgrade` (not from a preamble), follow Steps 2-6 above. If already on the latest version, tell the user: "You're already on the latest version (v{version})."
|