Skill Tracer
Skills › gstack › gstack-upgrade

gstack-upgrade

skill · 419 lines · MIT · gstack-upgrade/SKILL.md

The facts

Its description

Upgrade gstack to the latest version. Triggers: upgrade gstack; update gstack version; get latest gstack

The description the agent reads to decide when to use it. Phrases the author says should start it.

From its settingsline 4 line 5

When it starts

It starts when someone asks to upgrade or update gstack to the latest version, and it is also pulled in by other skills' preambles when they detect that an upgrade is available (the file says its inline flow is referenced by all skill preambles on UPGRADE_AVAILABLE).

Things a person might say (the model's guesses)

  • “upgrade gstack”
  • “can you update gstack to the latest version?”
  • “get me the latest gstack”

A model's summary of when it is used.

A model's reading

Tools it may use, or may not

allowed-tools: Bash, Read, Write, AskUserQuestion

Tools it may use while it runs without asking you first.

From its settingsline 9

Runs scripts

bin/gstack-config, bin/gstack-paths (first 5 of 20 lines)

Scripts the text names. Found by matching words, so treat them as pointers.

Found by matching wordsline 32 line 47 line 53 line 74 line 76

Stops for a person

4 lines stop to ask a person

Lines that stop and wait for a person before going on. Found by matching words, so treat them as pointers.

Found by matching wordsline 26 line 36 line 38 line 191

What leads to it

Other skills that hand off to this one, call it, require it or offer it instead, as a model read them.

A model's reading

Licence

MIT, from LICENSE

The terms its author shares it under, which let it be shown here.

From the repositorylicence text

Other settings

version: 1.1.0

More settings at the top of the file, shown as written.

From its settingsline 3
Other files in this skill (16) Close

The text

Open on GitHub

Most marks come from matching words in the file, so treat them as pointers.

1---
2name: gstack-upgrade
3version: 1.1.0
4description: Upgrade gstack to the latest version.
5triggers:
6 - upgrade gstack
7 - update gstack version
8 - get latest gstack
9allowed-tools:
10 - Bash
11 - Read
12 - Write
13 - AskUserQuestion
14---
15<!-- AUTO-GENERATED from SKILL.md.tmpl — do not edit directly -->
16<!-- Regenerate: bun run gen:skill-docs -->
18# /gstack-upgrade
20Upgrade gstack to the latest version and show what's new.

<!-- AUTO-GENERATED from SKILL.md.tmpl — do not edit directly --> <!-- Regenerate: bun run gen:skill-docs -->

/gstack-upgrade

Upgrade gstack to the latest version and show what's new.

Raw lines 1 to 21
22## Inline upgrade flow
24This section is referenced by all skill preambles when they detect `UPGRADE_AVAILABLE`.

Inline upgrade flow

This section is referenced by all skill preambles when they detect UPGRADE_AVAILABLE.

Raw lines 22 to 25
26### Step 1: Ask the user (or auto-upgrade)
28First, check if auto-upgrade is enabled:
29```bash
30_AUTO=""
31[ "${GSTACK_AUTO_UPGRADE:-}" = "1" ] && _AUTO="true"
32[ -z "$_AUTO" ] && _AUTO=$(~/.claude/skills/gstack/bin/gstack-config get auto_upgrade 2>/dev/null || true)
33echo "AUTO_UPGRADE=$_AUTO"
34```
36**If `AUTO_UPGRADE=true` or `AUTO_UPGRADE=1`:** Skip AskUserQuestion. Log "Auto-upgrading gstack v{old} → v{new}..." and proceed directly to Step 2. On setup failure, follow Step 4's install-specific recovery: vendored installs restore their backup; git installs stop with the pre-upgrade commit recorded, without a destructive reset. Never claim restoration unless it actually succeeded.
38**Otherwise**, use AskUserQuestion:
39- Question: "gstack **v{new}** is available (you're on v{old}). Upgrade now?"
40 Four fields (`UPGRADE_AVAILABLE <old> <old>+<n> <sha>`, main moved): ask "gstack main is **{n} commit(s)** past v{old} (at {sha}). Upgrade now?"
41- Options: ["Yes, upgrade now", "Always keep me up to date", "Not now", "Never ask again"]
43**If "Yes, upgrade now":** Proceed to Step 2.
45**If "Always keep me up to date":**
46```bash
47~/.claude/skills/gstack/bin/gstack-config set auto_upgrade true
48```
49Tell user: "Auto-upgrade enabled. Future updates will install automatically." Then proceed to Step 2.
51**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.
52```bash
53GSTACK_STATE_ROOT=$(~/.claude/skills/gstack/bin/gstack-paths --get GSTACK_STATE_ROOT); : "${GSTACK_STATE_ROOT:?gstack-paths failed; reinstall with ./setup or /gstack-upgrade}"
54_SNOOZE_FILE="$GSTACK_STATE_ROOT/update-snoozed"
55_REMOTE_VER="{new}"
56_CUR_LEVEL=0
57if [ -f "$_SNOOZE_FILE" ]; then
58 _SNOOZED_VER=$(awk '{print $(1)}' "$_SNOOZE_FILE")
59 if [ "$_SNOOZED_VER" = "$_REMOTE_VER" ]; then
60 _CUR_LEVEL=$(awk '{print $(2)}' "$_SNOOZE_FILE")
61 case "$_CUR_LEVEL" in *[!0-9]*) _CUR_LEVEL=0 ;; esac
62 fi
63fi
64_NEW_LEVEL=$((_CUR_LEVEL + 1))
65[ "$_NEW_LEVEL" -gt 3 ] && _NEW_LEVEL=3
66echo "$_REMOTE_VER $_NEW_LEVEL $(date +%s)" > "$_SNOOZE_FILE"
67```
68Note: `{new}` is the remote version from the `UPGRADE_AVAILABLE` output — substitute it from the update check result. On a four-field line use the SHA (fourth field) as `{new}`, so the snooze ends when main moves.
70Tell 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."
72**If "Never ask again":**
73```bash
74~/.claude/skills/gstack/bin/gstack-config set update_check false
75```
76Tell user: "Update checks disabled. Run `~/.claude/skills/gstack/bin/gstack-config set update_check true` to re-enable."
77Continue with the current skill.

Step 1: Ask the user (or auto-upgrade)

First, check if auto-upgrade is enabled:

_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. On setup failure, follow Step 4's install-specific recovery: vendored installs restore their backup; git installs stop with the pre-upgrade commit recorded, without a destructive reset. Never claim restoration unless it actually succeeded.

Otherwise, use AskUserQuestion:

  • Question: "gstack v{new} is available (you're on v{old}). Upgrade now?" Four fields (UPGRADE_AVAILABLE <old> <old>+<n> <sha>, main moved): ask "gstack main is {n} commit(s) past v{old} (at {sha}). 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":

~/.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.

GSTACK_STATE_ROOT=$(~/.claude/skills/gstack/bin/gstack-paths --get GSTACK_STATE_ROOT); : "${GSTACK_STATE_ROOT:?gstack-paths failed; reinstall with ./setup or /gstack-upgrade}"
_SNOOZE_FILE="$GSTACK_STATE_ROOT/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. On a four-field line use the SHA (fourth field) as {new}, so the snooze ends when main moves.

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":

~/.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.

Raw lines 26 to 78
Involves a person Ask the user :26
Runs code bin/gstack-config :32
Involves a person AskUserQuestion :36
Names a skill gstack :47
Runs code bin/gstack-paths :53
79### Step 2: Detect install type
81```bash
82if [ -d "$HOME/.claude/skills/gstack/.git" ]; then
83 INSTALL_TYPE="global-git"
84 INSTALL_DIR="$HOME/.claude/skills/gstack"
85elif [ -d "$HOME/.gstack/repos/gstack/.git" ]; then
86 INSTALL_TYPE="global-git"
87 INSTALL_DIR="$HOME/.gstack/repos/gstack"
88elif [ -d ".claude/skills/gstack/.git" ]; then
89 INSTALL_TYPE="local-git"
90 INSTALL_DIR=".claude/skills/gstack"
91elif [ -d ".agents/skills/gstack/.git" ]; then
92 INSTALL_TYPE="local-git"
93 INSTALL_DIR=".agents/skills/gstack"
94elif [ -d ".claude/skills/gstack" ]; then
95 INSTALL_TYPE="vendored"
96 INSTALL_DIR=".claude/skills/gstack"
97elif [ -d "$HOME/.claude/skills/gstack" ]; then
98 INSTALL_TYPE="vendored-global"
99 INSTALL_DIR="$HOME/.claude/skills/gstack"
100elif _SRC=$(~/.claude/skills/gstack/bin/gstack-paths --get GSTACK_STATE_ROOT 2>/dev/null) && _SRC=$(awk -F '\t' '$(1) == "claude" && $(6) != "-" { print $(6); exit }' "$_SRC/installs.tsv" 2>/dev/null) && [ -d "$_SRC/.git" ]; then
101 # The install registry names the checkout setup activated for this host (e.g. a ~/gstack clone).
102 INSTALL_TYPE="global-git"
103 INSTALL_DIR="$_SRC"
104else
105 echo "ERROR: gstack not found"
106 exit 1
107fi
108INSTALL_DIR=$(cd -- "$INSTALL_DIR" && pwd -P) || { echo "ERROR: cannot enter the gstack install directory" >&2; exit 1; }
109echo "Install type: $INSTALL_TYPE at $INSTALL_DIR"
110```
112The install type and the absolute directory printed above are used in all subsequent steps.
113Carry `INSTALL_TYPE`, `INSTALL_DIR`, `OLD_VERSION`, and later `UPSTREAM_REF` and `NEW_VERSION` forward explicitly: tool calls may run in fresh shells, so start each later block by assigning them from the captured output (for example `INSTALL_DIR=/abs/path/printed/above`). Do not rely on a prior call's working directory or shell variables. Every block that changes files first checks `INSTALL_DIR` and stops before any git command when it is unset, empty, missing, unreadable, or not gstack's own checkout.

Step 2: Detect install type

if [ -d "$HOME/.claude/skills/gstack/.git" ]; then
  INSTALL_TYPE="global-git"
  INSTALL_DIR="$HOME/.claude/skills/gstack"
elif [ -d "$HOME/.gstack/repos/gstack/.git" ]; then
  INSTALL_TYPE="global-git"
  INSTALL_DIR="$HOME/.gstack/repos/gstack"
elif [ -d ".claude/skills/gstack/.git" ]; then
  INSTALL_TYPE="local-git"
  INSTALL_DIR=".claude/skills/gstack"
elif [ -d ".agents/skills/gstack/.git" ]; then
  INSTALL_TYPE="local-git"
  INSTALL_DIR=".agents/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"
elif _SRC=$(~/.claude/skills/gstack/bin/gstack-paths --get GSTACK_STATE_ROOT 2>/dev/null) && _SRC=$(awk -F '\t' '$(1) == "claude" && $(6) != "-" { print $(6); exit }' "$_SRC/installs.tsv" 2>/dev/null) && [ -d "$_SRC/.git" ]; then
  # The install registry names the checkout setup activated for this host (e.g. a ~/gstack clone).
  INSTALL_TYPE="global-git"
  INSTALL_DIR="$_SRC"
else
  echo "ERROR: gstack not found"
  exit 1
fi
INSTALL_DIR=$(cd -- "$INSTALL_DIR" && pwd -P) || { echo "ERROR: cannot enter the gstack install directory" >&2; exit 1; }
echo "Install type: $INSTALL_TYPE at $INSTALL_DIR"

The install type and the absolute directory printed above are used in all subsequent steps. Carry INSTALL_TYPE, INSTALL_DIR, OLD_VERSION, and later UPSTREAM_REF and NEW_VERSION forward explicitly: tool calls may run in fresh shells, so start each later block by assigning them from the captured output (for example INSTALL_DIR=/abs/path/printed/above). Do not rely on a prior call's working directory or shell variables. Every block that changes files first checks INSTALL_DIR and stops before any git command when it is unset, empty, missing, unreadable, or not gstack's own checkout.

Raw lines 79 to 114
Runs code bin/gstack-paths :100
115### Step 3: Save old version
117Use the install directory from Step 2's output below:
119```bash
120OLD_VERSION=$(cat "${INSTALL_DIR:?INSTALL_DIR is not set: re-run Step 2 and substitute the printed path}/VERSION" 2>/dev/null || echo "unknown")
121echo "OLD_VERSION=$OLD_VERSION"
122```

Step 3: Save old version

Use the install directory from Step 2's output below:

OLD_VERSION=$(cat "${INSTALL_DIR:?INSTALL_DIR is not set: re-run Step 2 and substitute the printed path}/VERSION" 2>/dev/null || echo "unknown")
echo "OLD_VERSION=$OLD_VERSION"
Raw lines 115 to 123
124### Step 4: Upgrade
126Use the install type and directory detected in Step 2:
128**For git installs** (global-git, local-git):
130Fast-forward first, through `bin/gstack-ff-update`, the same code the
131session-update auto-upgrade uses: local edits that merge cleanly ride over the
132update, and an edit that conflicts (or a staged change, or an unmerged file)
133is saved in a rescue ref instead of being left as conflict markers:
134```bash
135cd -- "${INSTALL_DIR:?INSTALL_DIR is not set: re-run Step 2 and substitute the printed path}" || exit 1
136{ [ -f VERSION ] && [ -f setup ] && [ -f bin/gstack-config ] && _p=$(git rev-parse --show-prefix 2>/dev/null) && [ -z "$_p" ] && [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true ]; } || { echo "ERROR: $INSTALL_DIR is not a gstack checkout; nothing was changed. Re-run Step 2." >&2; exit 1; }
137git fetch origin
138# Channel ref (docs/releases.md): origin/stable for a team install, else origin/main
139_CH=$(bash bin/gstack-update-channel.sh --fetch-ref 2>&1) || _CH=origin/main
140echo "$_CH"; UPSTREAM_REF=$(printf '%s\n' "$_CH" | tail -1)
141echo "UPSTREAM_REF=${UPSTREAM_REF:=origin/main}"
142# Same pre-advance check as the auto-updater: the incoming release's Bun floor,
143# judged by bash whatever this tool shell is (zsh does not word-split).
144HOLD=$(UPSTREAM_REF="$UPSTREAM_REF" bash -c '. bin/gstack-bun-version.sh && gstack_bun_incoming_hold . "$UPSTREAM_REF"' 2>/dev/null) && { case "$HOLD" in bun-version-unreadable*) echo "BUN_VERSION_UNREADABLE: $HOLD; nothing was changed" >&2 ;; *) echo "BUN_TOO_OLD: $HOLD; nothing was changed" >&2 ;; esac; exit 1; }
145PRE_UPGRADE_COMMIT=$(git rev-parse HEAD)
146echo "PRE_UPGRADE_COMMIT=$PRE_UPGRADE_COMMIT"
147# Past the release (by ancestry, or by VERSION in a depth-1 clone): wait for stable; nothing moves back.
148if [ "$UPSTREAM_REF" = origin/stable ] && [ "$(git rev-parse origin/stable)" != "$PRE_UPGRADE_COMMIT" ] && ! git merge-base --is-ancestor HEAD origin/stable 2>/dev/null \
149 && { git merge-base --is-ancestor origin/stable HEAD 2>/dev/null || [ "$(printf '%s\n%s\n' "$(git show origin/stable:VERSION)" "$(cat VERSION)" | sort -V | tail -1)" = "$(cat VERSION)" ]; }; then echo "AHEAD_OF_STABLE"; exit 0; fi
150FF=$(bash bin/gstack-ff-update . "$UPSTREAM_REF"); FF_RC=$?
151echo "$FF"
152case "$FF_RC" in
153 0) if ./setup --refresh-registered; then echo "FF_OK"; else echo "SETUP_FAILED: git update succeeded; stop and inspect setup output (previous commit: $PRE_UPGRADE_COMMIT)" >&2; exit 1; fi ;;
154 4) echo "FF_REFUSED" ;;
155 *) echo "FF_STOPPED: $FF" >&2; exit 1 ;;
156esac
157```
159Setup's `--refresh-registered` refreshes every install this checkout
160registered (each host, global and this project's), prints the source first,
161and ends with an `Upgrade summary` of one row per install. Relay those rows
162as printed. A `failed` row means that host kept its previous install; give
163its retry command and never say every host was refreshed. A `skipped` row
164belongs to another checkout or project; pass on its command, do not run it.
166If the output ends with `FF_OK`, the upgrade is done — skip the fallback
167below entirely. When the line before it reads
168`rescued <old> <new> refs/gstack/rescue/<oid> unmerged=<0|1>`, tell the user
169their conflicting local edits were saved there and relay the `Inspect`,
170`Export` and `Delete` commands the script printed (export into a scratch
171checkout with `git apply -3`, never `stash apply` in the install;
172`unmerged=1` means the rescue needs manual resolution).
173On `FF_STOPPED`, STOP and relay the reason: nothing was changed.
174On `AHEAD_OF_STABLE`, STOP: the checkout is already past the latest stable release, so nothing changes until the next cut (`gstack-config set update_channel main` follows every merge). On a `fetching origin/stable failed` line above, STOP and relay it; nothing was changed.
175`ff-busy` means another gstack update is running (retry in a minute);
176`autostash-unrecoverable` names what is in the way (an untracked file the
177release adds, or another git command); `index-unreadable` means the checkout's
178index is damaged.
179On `BUN_TOO_OLD`, STOP: tell the user to run `bun upgrade`, then /gstack-upgrade again.
180On `BUN_VERSION_UNREADABLE`, STOP: `bun --version` did not print a version gstack can read, so `bun upgrade` may not run either; tell the user to reinstall Bun from https://bun.sh (`curl -fsSL https://bun.sh/install | bash` in Git Bash or a macOS/Linux terminal), check that `bun --version` prints a version such as 1.4.2, then run /gstack-upgrade again (docs/troubleshooting.md#bun-version-unreadable).
181On `SETUP_FAILED`, STOP; keep user changes and report the recovery commit. There is no `.bak` on the git path. Do not enter the divergence fallback merely because setup failed. Enter it only on `FF_REFUSED` (local commits or a diverged history); network/auth failures stop for repair, not reset.
183**Fallback (ff-only refused — local commits or divergence).** `git reset
184--hard` DESTROYS things: a clean tree with unpushed local commits still loses
185those commits. Gate it:
1871. Run `git status --porcelain` and `git rev-list "${UPSTREAM_REF:?}"..HEAD --oneline`
188 in `$INSTALL_DIR`.
1892. If BOTH are empty, the reset is provably safe — run the fallback block
190 below without asking.
1913. Otherwise ask via AskUserQuestion (one-way door — destructive), listing
192 exactly what will be discarded: each dirty file and each unpushed commit
193 by hash + subject. Options: **A)** Discard them and upgrade (reset) —
194 requires the explicit letter; **B)** Abort the upgrade so the user can
195 rescue their work first (recommended when local commits exist). Never
196 proceed on a vague reply.
198```bash
199cd -- "${INSTALL_DIR:?INSTALL_DIR is not set: re-run Step 2 and substitute the printed path}" || exit 1
200{ [ -f VERSION ] && [ -f setup ] && [ -f bin/gstack-config ] && _p=$(git rev-parse --show-prefix 2>/dev/null) && [ -z "$_p" ] && [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true ]; } || { echo "ERROR: $INSTALL_DIR is not a gstack checkout; nothing was changed. Re-run Step 2." >&2; exit 1; }
201# Regenerable render-footprint dirt (setup re-renders it) never goes into the stash.
202git checkout -- 'SKILL.md' '*/SKILL.md' '*/sections/*.md' 2>/dev/null || true
203STASH_OUTPUT=$(git stash 2>&1)
204git reset --hard "${UPSTREAM_REF:?UPSTREAM_REF is not set: substitute the value Step 4 printed}"
205./setup --refresh-registered
206```
207If `$STASH_OUTPUT` contains "Saved working directory", warn the user: "Note: local changes were stashed (any modified generated SKILL.md/sections files were discarded first — they regenerate on setup). Run `git stash pop` in the skill directory to restore your own changes."
209**For vendored installs** (vendored, vendored-global):
210```bash
211(cd -- "${INSTALL_DIR:?INSTALL_DIR is not set: re-run Step 2 and substitute the printed path}" && [ -f VERSION ] && [ -f setup ] && [ -f bin/gstack-config ]) || { echo "ERROR: INSTALL_DIR=${INSTALL_DIR:-} is not a gstack install; nothing was changed. Re-run Step 2." >&2; exit 1; }
212# A stale .bak from a previously crashed upgrade would make the mv below NEST
213# the live install inside it and the failure-restore arm would "restore" the
214# stale backup. It may also be the only good copy from that crashed run —
215# abort and let the human inspect, never delete it silently.
216[ -e "$INSTALL_DIR.bak" ] && { echo "ERROR: stale backup exists at $INSTALL_DIR.bak (from a previous failed upgrade?) — inspect it, salvage/remove it, then re-run." >&2; exit 1; }
217TMP_DIR=$(mktemp -d "${TMPDIR:-/tmp}/gstack-upgrade.XXXXXX") || { echo "ERROR: mktemp failed — aborting upgrade (install untouched)." >&2; exit 1; }
218git clone --depth 1 https://github.com/garrytan/gstack.git "$TMP_DIR/gstack" || { echo "ERROR: clone failed — aborting upgrade (install untouched)." >&2; rm -rf "$TMP_DIR"; exit 1; }
219mv "$INSTALL_DIR" "$INSTALL_DIR.bak" || { rm -rf "$TMP_DIR"; exit 1; }
220if mv "$TMP_DIR/gstack" "$INSTALL_DIR"; then
221 if (cd "$INSTALL_DIR" && ./setup --refresh-registered); then
222 rm -rf "$INSTALL_DIR.bak" "$TMP_DIR"
223 else
224 rm -rf "$INSTALL_DIR"
225 mv "$INSTALL_DIR.bak" "$INSTALL_DIR" || { echo "ERROR: restore failed; backup retained." >&2; exit 1; }
226 rm -rf "$TMP_DIR"
227 echo "ERROR: setup failed; previous install restored." >&2
228 exit 1
229 fi
230else
231 mv "$INSTALL_DIR.bak" "$INSTALL_DIR"
232 echo "ERROR: swap failed — previous install restored; upgrade aborted." >&2
233 rm -rf "$TMP_DIR"
234 exit 1
235fi
236```

Step 4: Upgrade

Use the install type and directory detected in Step 2:

For git installs (global-git, local-git):

Fast-forward first, through bin/gstack-ff-update, the same code the session-update auto-upgrade uses: local edits that merge cleanly ride over the update, and an edit that conflicts (or a staged change, or an unmerged file) is saved in a rescue ref instead of being left as conflict markers:

cd -- "${INSTALL_DIR:?INSTALL_DIR is not set: re-run Step 2 and substitute the printed path}" || exit 1
{ [ -f VERSION ] && [ -f setup ] && [ -f bin/gstack-config ] && _p=$(git rev-parse --show-prefix 2>/dev/null) && [ -z "$_p" ] && [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true ]; } || { echo "ERROR: $INSTALL_DIR is not a gstack checkout; nothing was changed. Re-run Step 2." >&2; exit 1; }
git fetch origin
# Channel ref (docs/releases.md): origin/stable for a team install, else origin/main
_CH=$(bash bin/gstack-update-channel.sh --fetch-ref 2>&1) || _CH=origin/main
echo "$_CH"; UPSTREAM_REF=$(printf '%s\n' "$_CH" | tail -1)
echo "UPSTREAM_REF=${UPSTREAM_REF:=origin/main}"
# Same pre-advance check as the auto-updater: the incoming release's Bun floor,
# judged by bash whatever this tool shell is (zsh does not word-split).
HOLD=$(UPSTREAM_REF="$UPSTREAM_REF" bash -c '. bin/gstack-bun-version.sh && gstack_bun_incoming_hold . "$UPSTREAM_REF"' 2>/dev/null) && { case "$HOLD" in bun-version-unreadable*) echo "BUN_VERSION_UNREADABLE: $HOLD; nothing was changed" >&2 ;; *) echo "BUN_TOO_OLD: $HOLD; nothing was changed" >&2 ;; esac; exit 1; }
PRE_UPGRADE_COMMIT=$(git rev-parse HEAD)
echo "PRE_UPGRADE_COMMIT=$PRE_UPGRADE_COMMIT"
# Past the release (by ancestry, or by VERSION in a depth-1 clone): wait for stable; nothing moves back.
if [ "$UPSTREAM_REF" = origin/stable ] && [ "$(git rev-parse origin/stable)" != "$PRE_UPGRADE_COMMIT" ] && ! git merge-base --is-ancestor HEAD origin/stable 2>/dev/null \
  && { git merge-base --is-ancestor origin/stable HEAD 2>/dev/null || [ "$(printf '%s\n%s\n' "$(git show origin/stable:VERSION)" "$(cat VERSION)" | sort -V | tail -1)" = "$(cat VERSION)" ]; }; then echo "AHEAD_OF_STABLE"; exit 0; fi
FF=$(bash bin/gstack-ff-update . "$UPSTREAM_REF"); FF_RC=$?
echo "$FF"
case "$FF_RC" in
  0) if ./setup --refresh-registered; then echo "FF_OK"; else echo "SETUP_FAILED: git update succeeded; stop and inspect setup output (previous commit: $PRE_UPGRADE_COMMIT)" >&2; exit 1; fi ;;
  4) echo "FF_REFUSED" ;;
  *) echo "FF_STOPPED: $FF" >&2; exit 1 ;;
esac

Setup's --refresh-registered refreshes every install this checkout registered (each host, global and this project's), prints the source first, and ends with an Upgrade summary of one row per install. Relay those rows as printed. A failed row means that host kept its previous install; give its retry command and never say every host was refreshed. A skipped row belongs to another checkout or project; pass on its command, do not run it.

If the output ends with FF_OK, the upgrade is done — skip the fallback below entirely. When the line before it reads rescued <old> <new> refs/gstack/rescue/<oid> unmerged=<0|1>, tell the user their conflicting local edits were saved there and relay the Inspect, Export and Delete commands the script printed (export into a scratch checkout with git apply -3, never stash apply in the install; unmerged=1 means the rescue needs manual resolution). On FF_STOPPED, STOP and relay the reason: nothing was changed. On AHEAD_OF_STABLE, STOP: the checkout is already past the latest stable release, so nothing changes until the next cut (gstack-config set update_channel main follows every merge). On a fetching origin/stable failed line above, STOP and relay it; nothing was changed. ff-busy means another gstack update is running (retry in a minute); autostash-unrecoverable names what is in the way (an untracked file the release adds, or another git command); index-unreadable means the checkout's index is damaged. On BUN_TOO_OLD, STOP: tell the user to run bun upgrade, then /gstack-upgrade again. On BUN_VERSION_UNREADABLE, STOP: bun --version did not print a version gstack can read, so bun upgrade may not run either; tell the user to reinstall Bun from https://bun.sh (curl -fsSL https://bun.sh/install | bash in Git Bash or a macOS/Linux terminal), check that bun --version prints a version such as 1.4.2, then run /gstack-upgrade again (docs/troubleshooting.md#bun-version-unreadable). On SETUP_FAILED, STOP; keep user changes and report the recovery commit. There is no .bak on the git path. Do not enter the divergence fallback merely because setup failed. Enter it only on FF_REFUSED (local commits or a diverged history); network/auth failures stop for repair, not reset.

Fallback (ff-only refused — local commits or divergence). git reset --hard DESTROYS things: a clean tree with unpushed local commits still loses those commits. Gate it:

  1. Run git status --porcelain and git rev-list "${UPSTREAM_REF:?}"..HEAD --oneline in $INSTALL_DIR.
  2. If BOTH are empty, the reset is provably safe — run the fallback block below without asking.
  3. Otherwise ask via AskUserQuestion (one-way door — destructive), listing exactly what will be discarded: each dirty file and each unpushed commit by hash + subject. Options: A) Discard them and upgrade (reset) — requires the explicit letter; B) Abort the upgrade so the user can rescue their work first (recommended when local commits exist). Never proceed on a vague reply.
cd -- "${INSTALL_DIR:?INSTALL_DIR is not set: re-run Step 2 and substitute the printed path}" || exit 1
{ [ -f VERSION ] && [ -f setup ] && [ -f bin/gstack-config ] && _p=$(git rev-parse --show-prefix 2>/dev/null) && [ -z "$_p" ] && [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true ]; } || { echo "ERROR: $INSTALL_DIR is not a gstack checkout; nothing was changed. Re-run Step 2." >&2; exit 1; }
# Regenerable render-footprint dirt (setup re-renders it) never goes into the stash.
git checkout -- 'SKILL.md' '*/SKILL.md' '*/sections/*.md' 2>/dev/null || true
STASH_OUTPUT=$(git stash 2>&1)
git reset --hard "${UPSTREAM_REF:?UPSTREAM_REF is not set: substitute the value Step 4 printed}"
./setup --refresh-registered

If $STASH_OUTPUT contains "Saved working directory", warn the user: "Note: local changes were stashed (any modified generated SKILL.md/sections files were discarded first — they regenerate on setup). Run git stash pop in the skill directory to restore your own changes."

For vendored installs (vendored, vendored-global):

(cd -- "${INSTALL_DIR:?INSTALL_DIR is not set: re-run Step 2 and substitute the printed path}" && [ -f VERSION ] && [ -f setup ] && [ -f bin/gstack-config ]) || { echo "ERROR: INSTALL_DIR=${INSTALL_DIR:-} is not a gstack install; nothing was changed. Re-run Step 2." >&2; exit 1; }
# A stale .bak from a previously crashed upgrade would make the mv below NEST
# the live install inside it and the failure-restore arm would "restore" the
# stale backup. It may also be the only good copy from that crashed run —
# abort and let the human inspect, never delete it silently.
[ -e "$INSTALL_DIR.bak" ] && { echo "ERROR: stale backup exists at $INSTALL_DIR.bak (from a previous failed upgrade?) — inspect it, salvage/remove it, then re-run." >&2; exit 1; }
TMP_DIR=$(mktemp -d "${TMPDIR:-/tmp}/gstack-upgrade.XXXXXX") || { echo "ERROR: mktemp failed — aborting upgrade (install untouched)." >&2; exit 1; }
git clone --depth 1 https://github.com/garrytan/gstack.git "$TMP_DIR/gstack" || { echo "ERROR: clone failed — aborting upgrade (install untouched)." >&2; rm -rf "$TMP_DIR"; exit 1; }
mv "$INSTALL_DIR" "$INSTALL_DIR.bak" || { rm -rf "$TMP_DIR"; exit 1; }
if mv "$TMP_DIR/gstack" "$INSTALL_DIR"; then
  if (cd "$INSTALL_DIR" && ./setup --refresh-registered); then
    rm -rf "$INSTALL_DIR.bak" "$TMP_DIR"
  else
    rm -rf "$INSTALL_DIR"
    mv "$INSTALL_DIR.bak" "$INSTALL_DIR" || { echo "ERROR: restore failed; backup retained." >&2; exit 1; }
    rm -rf "$TMP_DIR"
    echo "ERROR: setup failed; previous install restored." >&2
    exit 1
  fi
else
  mv "$INSTALL_DIR.bak" "$INSTALL_DIR"
  echo "ERROR: swap failed — previous install restored; upgrade aborted." >&2
  rm -rf "$TMP_DIR"
  exit 1
fi
Raw lines 124 to 237
Runs code bin/gstack-ff-update :130
Runs code bin/gstack-config :136
Runs code bash bin/gstack-update-channel.sh :139
Runs code bin/gstack-bun-version.sh :144
Involves a person AskUserQuestion :191
238### Step 4.5: Handle local vendored copy
240Use the install directory from Step 2. Check if there's also a local vendored copy, and whether team mode is active:
242```bash
243_RESOLVED_PRIMARY=$(cd -- "${INSTALL_DIR:?INSTALL_DIR is not set: re-run Step 2 and substitute the printed path}" && pwd -P) || exit 1
244_ROOT=$(git rev-parse --show-toplevel 2>/dev/null)
245LOCAL_GSTACK=""
246if [ -n "$_ROOT" ] && [ -d "$_ROOT/.claude/skills/gstack" ]; then
247 _RESOLVED_LOCAL=$(cd "$_ROOT/.claude/skills/gstack" && pwd -P)
248 if [ "$_RESOLVED_LOCAL" != "$_RESOLVED_PRIMARY" ]; then
249 LOCAL_GSTACK="$_ROOT/.claude/skills/gstack"
250 fi
251fi
252_TEAM_MODE=$(~/.claude/skills/gstack/bin/gstack-config get team_mode 2>/dev/null || echo "false")
253echo "LOCAL_GSTACK=$LOCAL_GSTACK"
254echo "TEAM_MODE=$_TEAM_MODE"
255```
257**If `LOCAL_GSTACK` is non-empty AND `TEAM_MODE` is `true`:** Remove the vendored copy. Team mode uses the global install as the single source of truth.
259```bash
260(cd -- "${LOCAL_GSTACK:?LOCAL_GSTACK is not set: re-run the detection block above and substitute the printed path}" && [ -f VERSION ] && [ -f setup ] && [ -f bin/gstack-config ]) || { echo "ERROR: LOCAL_GSTACK=${LOCAL_GSTACK:-} is not a gstack copy; nothing was changed." >&2; exit 1; }
261_ROOT=${LOCAL_GSTACK%/.claude/skills/gstack}
262{ [ "$_ROOT" != "$LOCAL_GSTACK" ] && cd -- "${_ROOT:?}" && _p=$(git rev-parse --show-prefix 2>/dev/null) && [ -z "$_p" ] && [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true ]; } || { echo "ERROR: $LOCAL_GSTACK is not the vendored copy at the root of a git repository; nothing was changed." >&2; exit 1; }
263git rm -r --cached .claude/skills/gstack/ 2>/dev/null || true
264if ! grep -qF '.claude/skills/gstack/' .gitignore 2>/dev/null; then
265 echo '.claude/skills/gstack/' >> .gitignore
266fi
267rm -rf "$LOCAL_GSTACK"
268```
269Tell user: "Removed vendored copy at `$LOCAL_GSTACK` (team mode active — global install is the source of truth). Commit the `.gitignore` change when ready."
271**If `LOCAL_GSTACK` is non-empty AND `TEAM_MODE` is NOT `true`:** Update it by copying from the freshly-upgraded primary install (same approach as README vendored install):
272```bash
273(cd -- "${INSTALL_DIR:?INSTALL_DIR is not set: re-run Step 2 and substitute the printed path}" && [ -f VERSION ] && [ -f setup ] && [ -f bin/gstack-config ]) || { echo "ERROR: INSTALL_DIR=${INSTALL_DIR:-} is not a gstack install; nothing was changed." >&2; exit 1; }
274(cd -- "${LOCAL_GSTACK:?LOCAL_GSTACK is not set: re-run the detection block above and substitute the printed path}" && [ -f VERSION ] && [ -f setup ] && [ -f bin/gstack-config ]) || { echo "ERROR: LOCAL_GSTACK=${LOCAL_GSTACK:-} is not a gstack copy; nothing was changed." >&2; exit 1; }
275[ -e "$LOCAL_GSTACK.bak" ] && { echo "ERROR: stale vendored backup; inspect it before retrying." >&2; exit 1; }
276mv "$LOCAL_GSTACK" "$LOCAL_GSTACK.bak" || exit 1
277if cp -Rf "$INSTALL_DIR" "$LOCAL_GSTACK" && rm -rf "$LOCAL_GSTACK/.git" && (cd "$LOCAL_GSTACK" && ./setup --refresh-registered); then
278 rm -rf "$LOCAL_GSTACK.bak"
279 echo "LOCAL_SYNC_OK"
280else
281 rm -rf "$LOCAL_GSTACK"
282 mv "$LOCAL_GSTACK.bak" "$LOCAL_GSTACK" || { echo "ERROR: restore failed; backup retained." >&2; exit 1; }
283 echo "ERROR: sync failed; previous vendored copy restored." >&2
284 exit 1
285fi
286```
287Only on `LOCAL_SYNC_OK`, tell user: "Also updated vendored copy at `$LOCAL_GSTACK` — commit `.claude/skills/gstack/` when you're ready." Otherwise stop and report the recovery outcome; do not continue migrations or announce success.

Step 4.5: Handle local vendored copy

Use the install directory from Step 2. Check if there's also a local vendored copy, and whether team mode is active:

_RESOLVED_PRIMARY=$(cd -- "${INSTALL_DIR:?INSTALL_DIR is not set: re-run Step 2 and substitute the printed path}" && pwd -P) || exit 1
_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)
  if [ "$_RESOLVED_LOCAL" != "$_RESOLVED_PRIMARY" ]; then
    LOCAL_GSTACK="$_ROOT/.claude/skills/gstack"
  fi
fi
_TEAM_MODE=$(~/.claude/skills/gstack/bin/gstack-config get team_mode 2>/dev/null || echo "false")
echo "LOCAL_GSTACK=$LOCAL_GSTACK"
echo "TEAM_MODE=$_TEAM_MODE"

**If LOCAL_GSTACK is non-empty AND TEAM_MODE is true:** Remove the vendored copy. Team mode uses the global install as the single source of truth.

(cd -- "${LOCAL_GSTACK:?LOCAL_GSTACK is not set: re-run the detection block above and substitute the printed path}" && [ -f VERSION ] && [ -f setup ] && [ -f bin/gstack-config ]) || { echo "ERROR: LOCAL_GSTACK=${LOCAL_GSTACK:-} is not a gstack copy; nothing was changed." >&2; exit 1; }
_ROOT=${LOCAL_GSTACK%/.claude/skills/gstack}
{ [ "$_ROOT" != "$LOCAL_GSTACK" ] && cd -- "${_ROOT:?}" && _p=$(git rev-parse --show-prefix 2>/dev/null) && [ -z "$_p" ] && [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true ]; } || { echo "ERROR: $LOCAL_GSTACK is not the vendored copy at the root of a git repository; nothing was changed." >&2; exit 1; }
git rm -r --cached .claude/skills/gstack/ 2>/dev/null || true
if ! grep -qF '.claude/skills/gstack/' .gitignore 2>/dev/null; then
  echo '.claude/skills/gstack/' >> .gitignore
fi
rm -rf "$LOCAL_GSTACK"

Tell user: "Removed vendored copy at $LOCAL_GSTACK (team mode active — global install is the source of truth). Commit the .gitignore change when ready."

**If LOCAL_GSTACK is non-empty AND TEAM_MODE is NOT true:** Update it by copying from the freshly-upgraded primary install (same approach as README vendored install):

(cd -- "${INSTALL_DIR:?INSTALL_DIR is not set: re-run Step 2 and substitute the printed path}" && [ -f VERSION ] && [ -f setup ] && [ -f bin/gstack-config ]) || { echo "ERROR: INSTALL_DIR=${INSTALL_DIR:-} is not a gstack install; nothing was changed." >&2; exit 1; }
(cd -- "${LOCAL_GSTACK:?LOCAL_GSTACK is not set: re-run the detection block above and substitute the printed path}" && [ -f VERSION ] && [ -f setup ] && [ -f bin/gstack-config ]) || { echo "ERROR: LOCAL_GSTACK=${LOCAL_GSTACK:-} is not a gstack copy; nothing was changed." >&2; exit 1; }
[ -e "$LOCAL_GSTACK.bak" ] && { echo "ERROR: stale vendored backup; inspect it before retrying." >&2; exit 1; }
mv "$LOCAL_GSTACK" "$LOCAL_GSTACK.bak" || exit 1
if cp -Rf "$INSTALL_DIR" "$LOCAL_GSTACK" && rm -rf "$LOCAL_GSTACK/.git" && (cd "$LOCAL_GSTACK" && ./setup --refresh-registered); then
  rm -rf "$LOCAL_GSTACK.bak"
  echo "LOCAL_SYNC_OK"
else
  rm -rf "$LOCAL_GSTACK"
  mv "$LOCAL_GSTACK.bak" "$LOCAL_GSTACK" || { echo "ERROR: restore failed; backup retained." >&2; exit 1; }
  echo "ERROR: sync failed; previous vendored copy restored." >&2
  exit 1
fi

Only on LOCAL_SYNC_OK, tell user: "Also updated vendored copy at $LOCAL_GSTACK — commit .claude/skills/gstack/ when you're ready." Otherwise stop and report the recovery outcome; do not continue migrations or announce success.

Raw lines 238 to 288
Runs code bin/gstack-config :252
289### Step 4.75: Run version migrations
291After `./setup`, run the migrations in `gstack-upgrade/migrations/` (idempotent
292`v{VERSION}.sh` scripts; CONTRIBUTING.md says how to add one) newer than the old
293version: they fix state `./setup` alone cannot (stale config, orphaned files).
295```bash
296MIGRATIONS_DIR="${INSTALL_DIR:?INSTALL_DIR is not set: re-run Step 2 and substitute the printed path}/gstack-upgrade/migrations"
297: "${OLD_VERSION:?OLD_VERSION is not set: substitute the value Step 3 printed}"
298if [ -d "$MIGRATIONS_DIR" ]; then
299 for migration in $(find "$MIGRATIONS_DIR" -maxdepth 1 -name 'v*.sh' -type f 2>/dev/null | sort -V); do
300 m_ver="$(basename "$migration" .sh | sed 's/^v//')"
301 if [ "$OLD_VERSION" != "unknown" ] && [ "$(printf '%s\n%s' "$OLD_VERSION" "$m_ver" | sort -V | head -1)" = "$OLD_VERSION" ] && [ "$OLD_VERSION" != "$m_ver" ]; then
302 echo "Running migration $m_ver..."
303 # Without GSTACK_INSTALL_DIR a migration that cleans the install assumes ~/.claude/skills/gstack.
304 GSTACK_INSTALL_DIR="$INSTALL_DIR" bash "$migration" || echo " Warning: migration $m_ver had errors (non-fatal)"
305 fi
306 done
307fi
308```

Step 4.75: Run version migrations

After ./setup, run the migrations in gstack-upgrade/migrations/ (idempotent v{VERSION}.sh scripts; CONTRIBUTING.md says how to add one) newer than the old version: they fix state ./setup alone cannot (stale config, orphaned files).

MIGRATIONS_DIR="${INSTALL_DIR:?INSTALL_DIR is not set: re-run Step 2 and substitute the printed path}/gstack-upgrade/migrations"
: "${OLD_VERSION:?OLD_VERSION is not set: substitute the value Step 3 printed}"
if [ -d "$MIGRATIONS_DIR" ]; then
  for migration in $(find "$MIGRATIONS_DIR" -maxdepth 1 -name 'v*.sh' -type f 2>/dev/null | sort -V); do
    m_ver="$(basename "$migration" .sh | sed 's/^v//')"
    if [ "$OLD_VERSION" != "unknown" ] && [ "$(printf '%s\n%s' "$OLD_VERSION" "$m_ver" | sort -V | head -1)" = "$OLD_VERSION" ] && [ "$OLD_VERSION" != "$m_ver" ]; then
      echo "Running migration $m_ver..."
      # Without GSTACK_INSTALL_DIR a migration that cleans the install assumes ~/.claude/skills/gstack.
      GSTACK_INSTALL_DIR="$INSTALL_DIR" bash "$migration" || echo "  Warning: migration $m_ver had errors (non-fatal)"
    fi
  done
fi
Raw lines 289 to 309
310### Step 4.8: Stop any stale daemon (unconditional)
312A browse daemon started before the upgrade keeps running the old binary (the
313reset and `./setup` do not stop it), so always run this step with the install
314directory from Step 2.
316```bash
317INSTALL_DIR_PLACEHOLDER="<install dir from Step 2>"
318NEW_HASH=$(cat "$INSTALL_DIR_PLACEHOLDER/browse/dist/.version" 2>/dev/null || echo "")
319_STATE_FILE="${BROWSE_STATE_FILE:-$(git rev-parse --show-toplevel 2>/dev/null || pwd)/.gstack/browse.json}"
320if [ -z "$NEW_HASH" ] || [ ! -f "$_STATE_FILE" ]; then
321 echo "DAEMON_CHECK=none (no state file or no fresh build hash)"
322else
323 DAEMON_PID=$(sed -n 's/.*"pid"[[:space:]]*:[[:space:]]*\([0-9][0-9]*\).*/\1/p' "$_STATE_FILE" | head -1)
324 DAEMON_PORT=$(sed -n 's/.*"port"[[:space:]]*:[[:space:]]*\([0-9][0-9]*\).*/\1/p' "$_STATE_FILE" | head -1)
325 OLD_HASH=$(sed -n 's/.*"binaryVersion"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$_STATE_FILE" | head -1)
326 if [ -z "$DAEMON_PID" ] || ! kill -0 "$DAEMON_PID" 2>/dev/null; then
327 echo "DAEMON_CHECK=dead (no live daemon to stop)"
328 elif [ "$OLD_HASH" = "$NEW_HASH" ]; then
329 echo "DAEMON_CHECK=current (daemon already runs the new binary)"
330 elif curl -fsS --max-time 2 "http://127.0.0.1:$DAEMON_PORT/health" 2>/dev/null | grep -q '"status":"healthy"'; then
331 echo "DAEMON_CHECK=stale-responsive pid=$DAEMON_PID hash=${OLD_HASH:-unknown} -> $NEW_HASH"
332 "$INSTALL_DIR_PLACEHOLDER/browse/dist/browse" stop && echo "DAEMON_STOPPED=yes"
333 else
334 echo "DAEMON_CHECK=stale-busy pid=$DAEMON_PID hash=${OLD_HASH:-unknown} -> $NEW_HASH"
335 fi
336fi
337```
339Substitute the install directory from Step 2, then act on `DAEMON_CHECK`:
3411. **`stale-responsive` + `DAEMON_STOPPED=yes`:** Tell the user "Stopped the
342 old browse daemon (binary {OLD_HASH} → {NEW_HASH}). The next browse command
343 starts a fresh daemon on the new binary."
3442. **`stale-busy`:** The daemon runs the old binary but is mid-work — DEFER to
345 it, never kill a busy daemon during upgrade. Tell the user: "A browse daemon
346 is still running the pre-upgrade binary ({OLD_HASH} → {NEW_HASH}) but is
347 busy right now. When it finishes, stop it with `browse stop` — or force it
348 immediately with `browse --force-restart stop` (loses that session's
349 tabs/cookies/logins)."
3503. **`none` / `dead` / `current`:** say nothing.

Step 4.8: Stop any stale daemon (unconditional)

A browse daemon started before the upgrade keeps running the old binary (the reset and ./setup do not stop it), so always run this step with the install directory from Step 2.

INSTALL_DIR_PLACEHOLDER="<install dir from Step 2>"
NEW_HASH=$(cat "$INSTALL_DIR_PLACEHOLDER/browse/dist/.version" 2>/dev/null || echo "")
_STATE_FILE="${BROWSE_STATE_FILE:-$(git rev-parse --show-toplevel 2>/dev/null || pwd)/.gstack/browse.json}"
if [ -z "$NEW_HASH" ] || [ ! -f "$_STATE_FILE" ]; then
  echo "DAEMON_CHECK=none (no state file or no fresh build hash)"
else
  DAEMON_PID=$(sed -n 's/.*"pid"[[:space:]]*:[[:space:]]*\([0-9][0-9]*\).*/\1/p' "$_STATE_FILE" | head -1)
  DAEMON_PORT=$(sed -n 's/.*"port"[[:space:]]*:[[:space:]]*\([0-9][0-9]*\).*/\1/p' "$_STATE_FILE" | head -1)
  OLD_HASH=$(sed -n 's/.*"binaryVersion"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$_STATE_FILE" | head -1)
  if [ -z "$DAEMON_PID" ] || ! kill -0 "$DAEMON_PID" 2>/dev/null; then
    echo "DAEMON_CHECK=dead (no live daemon to stop)"
  elif [ "$OLD_HASH" = "$NEW_HASH" ]; then
    echo "DAEMON_CHECK=current (daemon already runs the new binary)"
  elif curl -fsS --max-time 2 "http://127.0.0.1:$DAEMON_PORT/health" 2>/dev/null | grep -q '"status":"healthy"'; then
    echo "DAEMON_CHECK=stale-responsive pid=$DAEMON_PID hash=${OLD_HASH:-unknown} -> $NEW_HASH"
    "$INSTALL_DIR_PLACEHOLDER/browse/dist/browse" stop && echo "DAEMON_STOPPED=yes"
  else
    echo "DAEMON_CHECK=stale-busy pid=$DAEMON_PID hash=${OLD_HASH:-unknown} -> $NEW_HASH"
  fi
fi

Substitute the install directory from Step 2, then act on DAEMON_CHECK:

  1. **stale-responsive + DAEMON_STOPPED=yes:** Tell the user "Stopped the old browse daemon (binary {OLD_HASH} → {NEW_HASH}). The next browse command starts a fresh daemon on the new binary."
  2. **stale-busy:** The daemon runs the old binary but is mid-work — DEFER to it, never kill a busy daemon during upgrade. Tell the user: "A browse daemon is still running the pre-upgrade binary ({OLD_HASH} → {NEW_HASH}) but is busy right now. When it finishes, stop it with browse stop — or force it immediately with browse --force-restart stop (loses that session's tabs/cookies/logins)."
  3. **none / dead / current:** say nothing.
Raw lines 310 to 351
352### Step 5: Write marker + clear cache
354```bash
355GSTACK_STATE_ROOT=$(~/.claude/skills/gstack/bin/gstack-paths --get GSTACK_STATE_ROOT); : "${GSTACK_STATE_ROOT:?gstack-paths failed; reinstall with ./setup or /gstack-upgrade}"
356mkdir -p "$GSTACK_STATE_ROOT"
357echo "$OLD_VERSION" > "$GSTACK_STATE_ROOT"/just-upgraded-from
358rm -f "$GSTACK_STATE_ROOT"/last-update-check
359rm -f "$GSTACK_STATE_ROOT"/update-snoozed
360```

Step 5: Write marker + clear cache

GSTACK_STATE_ROOT=$(~/.claude/skills/gstack/bin/gstack-paths --get GSTACK_STATE_ROOT); : "${GSTACK_STATE_ROOT:?gstack-paths failed; reinstall with ./setup or /gstack-upgrade}"
mkdir -p "$GSTACK_STATE_ROOT"
echo "$OLD_VERSION" > "$GSTACK_STATE_ROOT"/just-upgraded-from
rm -f "$GSTACK_STATE_ROOT"/last-update-check
rm -f "$GSTACK_STATE_ROOT"/update-snoozed
Raw lines 352 to 361
Runs code bin/gstack-paths :355
362### Step 6: Show What's New
364Read `$INSTALL_DIR/CHANGELOG.md`. Find all version entries between the old version and the new version. Summarize as 5-7 bullets grouped by theme, user-facing changes first.
366Four fields: summarize `git -C "$INSTALL_DIR" log --oneline <PRE_UPGRADE_COMMIT>..HEAD` (≤7 bullets) as "gstack v{old}, main at {sha}".
368Format:
369```
370gstack v{new} — upgraded from v{old}!
372What's new:
373- [bullet 1]
374- [bullet 2]
375- ...
377Happy shipping!
378```

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, user-facing changes first.

Four fields: summarize git -C "$INSTALL_DIR" log --oneline <PRE_UPGRADE_COMMIT>..HEAD (≤7 bullets) as "gstack v{old}, main at {sha}".

Format:

gstack v{new} — upgraded from v{old}!

What's new:
- [bullet 1]
- [bullet 2]
- ...

Happy shipping!
Raw lines 362 to 379
380### Step 7: Continue
382Continue with the skill the user originally invoked; the upgrade is done.
384---

Step 7: Continue

Continue with the skill the user originally invoked; the upgrade is done.


Raw lines 380 to 385
386## Standalone usage
388When invoked directly as `/gstack-upgrade` (not from a preamble):
3901. Force a fresh update check (bypass cache):
391```bash
392~/.claude/skills/gstack/bin/gstack-update-check --force 2>/dev/null || \
393.claude/skills/gstack/bin/gstack-update-check --force 2>/dev/null || true
394```
3962. If `UPGRADE_AVAILABLE` (three or four fields): follow Steps 2-6 above.
398 If `CHECK_FAILED ...`: the remote version could not be read, so the update
399 status is unknown. Show the line (it names the URL that failed) and tell the
400 user the check failed; never report "already on the latest version". Stop.
4023. If no output (primary is up to date): check for a stale local vendored copy.
404Run the Step 2 bash block above to detect the primary install type and directory (`INSTALL_TYPE` and `INSTALL_DIR`). Then run the Step 4.5 detection bash block above to check for a local vendored copy (`LOCAL_GSTACK`) and team mode status (`TEAM_MODE`).
406**If `LOCAL_GSTACK` is empty** (no local vendored copy): tell the user "You're already on the latest version (v{version})."
408**If `LOCAL_GSTACK` is non-empty AND `TEAM_MODE` is `true`:** Remove the vendored copy using the Step 4.5 team-mode removal bash block above. Tell user: "Global v{version} is up to date. Removed stale vendored copy (team mode active). Commit the `.gitignore` change when ready."
410**If `LOCAL_GSTACK` is non-empty AND `TEAM_MODE` is NOT `true`**, compare versions:
411```bash
412PRIMARY_VER=$(cat "${INSTALL_DIR:?INSTALL_DIR is not set: re-run Step 2 and substitute the printed path}/VERSION" 2>/dev/null || echo "unknown")
413LOCAL_VER=$(cat "${LOCAL_GSTACK:?LOCAL_GSTACK is not set: re-run the Step 4.5 detection block}/VERSION" 2>/dev/null || echo "unknown")
414echo "PRIMARY=$PRIMARY_VER LOCAL=$LOCAL_VER"
415```
417**If versions differ:** follow the Step 4.5 sync bash block above to update the local copy from the primary. Tell user: "Global v{PRIMARY_VER} is up to date. Updated local vendored copy from v{LOCAL_VER} → v{PRIMARY_VER}. Commit `.claude/skills/gstack/` when you're ready."
419**If versions match:** tell the user "You're on the latest version (v{PRIMARY_VER}). Global and local vendored copy are both up to date."

Standalone usage

When invoked directly as /gstack-upgrade (not from a preamble):

  1. Force a fresh update check (bypass cache):
~/.claude/skills/gstack/bin/gstack-update-check --force 2>/dev/null || \
.claude/skills/gstack/bin/gstack-update-check --force 2>/dev/null || true
  1. If UPGRADE_AVAILABLE (three or four fields): follow Steps 2-6 above.

If CHECK_FAILED ...: the remote version could not be read, so the update status is unknown. Show the line (it names the URL that failed) and tell the user the check failed; never report "already on the latest version". Stop.

  1. If no output (primary is up to date): check for a stale local vendored copy.

Run the Step 2 bash block above to detect the primary install type and directory (INSTALL_TYPE and INSTALL_DIR). Then run the Step 4.5 detection bash block above to check for a local vendored copy (LOCAL_GSTACK) and team mode status (TEAM_MODE).

**If LOCAL_GSTACK is empty** (no local vendored copy): tell the user "You're already on the latest version (v{version})."

**If LOCAL_GSTACK is non-empty AND TEAM_MODE is true:** Remove the vendored copy using the Step 4.5 team-mode removal bash block above. Tell user: "Global v{version} is up to date. Removed stale vendored copy (team mode active). Commit the .gitignore change when ready."

**If LOCAL_GSTACK is non-empty AND TEAM_MODE is NOT true**, compare versions:

PRIMARY_VER=$(cat "${INSTALL_DIR:?INSTALL_DIR is not set: re-run Step 2 and substitute the printed path}/VERSION" 2>/dev/null || echo "unknown")
LOCAL_VER=$(cat "${LOCAL_GSTACK:?LOCAL_GSTACK is not set: re-run the Step 4.5 detection block}/VERSION" 2>/dev/null || echo "unknown")
echo "PRIMARY=$PRIMARY_VER LOCAL=$LOCAL_VER"

If versions differ: follow the Step 4.5 sync bash block above to update the local copy from the primary. Tell user: "Global v{PRIMARY_VER} is up to date. Updated local vendored copy from v{LOCAL_VER} → v{PRIMARY_VER}. Commit .claude/skills/gstack/ when you're ready."

If versions match: tell the user "You're on the latest version (v{PRIMARY_VER}). Global and local vendored copy are both up to date."

Raw lines 386 to 419
Runs code bin/gstack-update-check :392

From garrytan/gstack at 3f79d81, 2026-11-01. Skills read by DeepSeek V4.1 Flash on 2026-11-04. Summary and techniques by Claude Opus 5.5 on 2026-11-06.