Skills › gstack › gstack-upgrade › v1.67.0.0.sh
v1.67.0.0.sh
73 lines · gstack-upgrade/migrations/v1.67.0.0.sh at 3f79d81
1#!/usr/bin/env bash
2# Migration: v1.67.0.0 — restore tracked files dirtied by the legacy in-place
3# gbrain render (#2569, F12).
4#
5# Why a migration: pre-v1.67, gbrain-enabled setups ran `gen:skill-docs:user
6# --host claude` IN PLACE inside the global install checkout
7# (~/.claude/skills/gstack), rewriting ~16 TRACKED SKILL.md files. The
8# checkout stayed permanently dirty, and every /gstack-upgrade `git stash`
9# saved a redundant snapshot of generated content — stashes that invite a
10# dangerous `git stash pop` of stale instruction markdown over a newer
11# version. v1.67 renders to an untracked out-dir (~/.gstack/render/claude)
12# instead, so this migration does the ONE-TIME cleanup of the legacy dirt:
13# `git checkout --` on the modified generated files.
14#
15# Restore scope is deliberately narrow: only UNSTAGED MODIFIED files whose
16# path is a SKILL.md or lives under a sections/ directory — the exact
17# footprint of the legacy render. Anything else a user changed by hand
18# (untracked files, staged work, non-generated edits) is left alone and
19# reported. setup's gbrain step re-renders the brain-aware variant into the
20# out-dir immediately after migrations run, so no capability is lost.
21#
22# Affected: global-git installs that ever ran ./setup or `gstack-config
23# gbrain-refresh` with gbrain detected, before v1.67.0.0.
24#
25# Idempotent: a clean checkout is a no-op. Non-fatal throughout.
26set -u
28INSTALL_DIR="${GSTACK_INSTALL_DIR:-$HOME/.claude/skills/gstack}"
30# Only operate on a real (non-symlink) git checkout that looks like gstack.
31[ -d "$INSTALL_DIR" ] || exit 0
32[ -L "$INSTALL_DIR" ] && exit 0
33[ -f "$INSTALL_DIR/VERSION" ] || exit 0
34git -C "$INSTALL_DIR" rev-parse --is-inside-work-tree >/dev/null 2>&1 || exit 0
36_DIRTY="$(git -C "$INSTALL_DIR" status --porcelain 2>/dev/null || true)"
37[ -n "$_DIRTY" ] || exit 0
39_RESTORED=0
40_LEFT=0
41while IFS= read -r _LINE; do
42 [ -n "$_LINE" ] || continue
43 _CODE="${_LINE:0:2}"
44 _PATH="${_LINE:3}"
45 # Legacy render footprint: unstaged modifications to generated markdown.
46 case "$_CODE" in
47 " M")
48 case "$_PATH" in
49 SKILL.md|*/SKILL.md|*/sections/*.md)
50 if git -C "$INSTALL_DIR" checkout -- "$_PATH" 2>/dev/null; then
51 _RESTORED=$((_RESTORED + 1))
52 else
53 _LEFT=$((_LEFT + 1))
54 fi
55 ;;
56 *) _LEFT=$((_LEFT + 1)) ;;
57 esac
58 ;;
59 *) _LEFT=$((_LEFT + 1)) ;;
60 esac
61done <<EOF_DIRTY
62$_DIRTY
63EOF_DIRTY
65if [ "$_RESTORED" -gt 0 ]; then
66 echo " v1.67.0.0: restored $_RESTORED tracked file(s) dirtied by the legacy in-place gbrain render (#2569)."
67 echo " Brain-aware blocks now render to ~/.gstack/render/claude — the checkout stays clean from here on."
68fi
69if [ "$_LEFT" -gt 0 ]; then
70 echo " v1.67.0.0: left $_LEFT non-render change(s) in $INSTALL_DIR untouched (not the legacy render footprint)."
71fi
73exit 0