Skills › gstack › gstack-upgrade › v1.17.0.0.sh
v1.17.0.0.sh
59 lines · gstack-upgrade/migrations/v1.17.0.0.sh at 3f79d81
1#!/usr/bin/env bash
2# Migration: v1.17.0.0 — Wire existing brain-sync repos as gbrain federated sources
3#
4# Pre-1.17.0.0 /setup-gbrain wrote ~/.gstack/consumers.json with a placeholder
5# `status: "pending"` and an empty `ingest_url`, expecting a gbrain HTTP
6# /ingest-repo endpoint that never shipped. This migration runs the real
7# wireup (gbrain sources add + worktree + initial sync) for users who
8# already opted into brain-sync but never got the gbrain side connected.
9#
10# Idempotent: safe to re-run. Skips when:
11# - User never opted into brain-sync (gbrain_sync_mode = off or unset)
12# - No ~/.gstack/.git (brain-init never ran)
13# - The wireup helper is missing on disk (broken install — defensive)
14#
15# Failure mode: invokes the helper WITHOUT --strict, so a missing/old gbrain
16# CLI is a benign skip rather than blocking the rest of /gstack-upgrade.
17set -euo pipefail
19if [ -z "${HOME:-}" ]; then
20 echo " [v1.17.0.0] HOME is unset or empty — skipping migration." >&2
21 exit 0
22fi
24SKILLS_DIR="${HOME}/.claude/skills"
25BIN_DIR="${SKILLS_DIR}/gstack/bin"
26CONFIG_BIN="${BIN_DIR}/gstack-config"
27WIREUP_BIN="${BIN_DIR}/gstack-gbrain-source-wireup"
29# Skip if user never opted into brain-sync.
30SYNC_MODE=""
31if [ -x "$CONFIG_BIN" ]; then
32 # Trim whitespace defensively: gstack-config can emit trailing newlines,
33 # which would mis-classify "off\n" as a non-empty non-off mode.
34 SYNC_MODE=$("$CONFIG_BIN" get gbrain_sync_mode 2>/dev/null | tr -d '[:space:]' || echo "")
35fi
36if [ "$SYNC_MODE" = "off" ] || [ -z "$SYNC_MODE" ]; then
37 exit 0
38fi
40# Skip if no brain-sync git repo exists.
41_gstack_migration_dir="${BASH_SOURCE[0]//\\//}"; _gstack_migration_dir="${_gstack_migration_dir%/*}"
42. "${_gstack_migration_dir}/../../bin/gstack-state-root.sh" 2>/dev/null || { echo "$0: cannot resolve the gstack state root: ${_gstack_migration_dir}/../../bin/gstack-state-root.sh is missing. fix: reinstall with ./setup or /gstack-upgrade (docs/state-root.md)" >&2; exit 1; }
43gstack_state_root_select
44if [ ! -d "$_gstack_sr_root/.git" ]; then
45 exit 0
46fi
48# Skip if helper missing (defensive — should always be present post-upgrade).
49if [ ! -x "$WIREUP_BIN" ]; then
50 echo " [v1.17.0.0] $WIREUP_BIN missing or non-executable — skipping wireup." >&2
51 exit 0
52fi
54echo " [v1.17.0.0] Wiring brain-sync repo into gbrain (federated source + initial sync)..."
56# No --strict: missing/old gbrain is a benign skip during a batch upgrade.
57"$WIREUP_BIN" || {
58 echo " [v1.17.0.0] Wireup exited non-zero — re-run manually with: $WIREUP_BIN" >&2
59}