Skill Tracer
Skills › gstack › gstack-upgrade › v1.37.0.0.sh

v1.37.0.0.sh

104 lines · gstack-upgrade/migrations/v1.37.0.0.sh at 3f79d81

1#!/usr/bin/env bash
2# Migration: v1.37.0.0 — split-engine gbrain (remote MCP brain + optional
3# local PGLite for code search per worktree).
4#
5# Per plan D5: prints a ONE-TIME discoverability notice for existing
6# Path 4 users who don't yet have a local engine. They learn that
7# symbol-aware code search (gbrain code-def / code-refs / code-callers)
8# is now available via /setup-gbrain Step 4.5 if they want it.
9#
10# When to print the notice (state match — all conditions must hold):
11# - ~/.claude.json declares mcpServers.gbrain.{type|transport} = http|sse|url
12# OR mcpServers.gbrain.url is set (remote-http MCP active)
13# - ~/.gbrain/config.json is absent (no local engine yet)
14# - User has not previously opted out via:
15# ~/.claude/skills/gstack/bin/gstack-config set local_code_index_offered true
17# When silent: anything else (Path 1/2/3 users, anyone already on PGLite,
18# anyone who opted out, anyone without remote-http MCP).
20# Idempotency: writes a touchfile at ~/.gstack/.migrations/v1.37.0.0.done
21# on completion. Re-running this script is silent if the touchfile exists,
22# OR if local_code_index_offered=true.
24# Heredoc delivery guard. bash 5.2+ writes a heredoc body <=64KiB through a
25# pipe in the forked child before exec, with no reader on the other end. On
26# macOS under pipe-KVA pressure a fresh pipe gets a 512-byte buffer, so any
27# body >=512B blocks write() forever and the script hangs at startup with no
28# output. Compat level 50 restores the tempfile path. These scripts are
29# bash-3.2-clean, so the compat level costs them nothing. Not exported: the
30# guard is per-script, and it survives `bash script.sh` call sites that
31# bypass the shebang.
32BASH_COMPAT=50
34set -euo pipefail
36if [ -z "${HOME:-}" ]; then
37 echo " [v1.37.0.0] HOME is unset — skipping migration." >&2
38 exit 0
39fi
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; GSTACK_HOME="$_gstack_sr_root"
44MIGRATIONS_DIR="$GSTACK_HOME/.migrations"
45DONE_TOUCH="$MIGRATIONS_DIR/v1.37.0.0.done"
46CONFIG_BIN="$HOME/.claude/skills/gstack/bin/gstack-config"
47CLAUDE_JSON="$HOME/.claude.json"
48GBRAIN_CONFIG="$HOME/.gbrain/config.json"
50mkdir -p "$MIGRATIONS_DIR"
52# Idempotency: already-ran skips silently.
53if [ -f "$DONE_TOUCH" ]; then
54 exit 0
55fi
57# User opt-out skips silently AND records done.
58if [ -x "$CONFIG_BIN" ]; then
59 if [ "$("$CONFIG_BIN" get local_code_index_offered 2>/dev/null)" = "true" ]; then
60 touch "$DONE_TOUCH"
61 exit 0
62 fi
63fi
65# State match: remote-http MCP active?
66is_remote_http_mcp() {
67 [ -f "$CLAUDE_JSON" ] || return 1
68 command -v jq >/dev/null 2>&1 || return 1
69 local mtype murl
70 mtype=$(jq -r '.mcpServers.gbrain.type // .mcpServers.gbrain.transport // empty' "$CLAUDE_JSON" 2>/dev/null)
71 murl=$(jq -r '.mcpServers.gbrain.url // empty' "$CLAUDE_JSON" 2>/dev/null)
72 case "$mtype" in
73 url|http|sse) return 0 ;;
74 esac
75 [ -n "$murl" ] && return 0
76 return 1
79# State match: local engine absent?
80is_local_engine_missing() {
81 [ ! -f "$GBRAIN_CONFIG" ]
84if is_remote_http_mcp && is_local_engine_missing; then
85 cat <<'NOTICE'
87 ┌──────────────────────────────────────────────────────────────────┐
88 │ gstack v1.37.0.0 — split-engine gbrain │
89 │ │
90 │ Symbol-aware code search is now available on this machine. │
91 │ Your remote brain at gbrain MCP keeps working as today; you can │
92 │ add a tiny local PGLite (~30s, no accounts) for `gbrain │
93 │ code-def` / `code-refs` / `code-callers` queries per worktree. │
94 │ │
95 │ Run /setup-gbrain to opt in at Step 4.5. Or skip this notice │
96 │ permanently: │
97 │ gstack-config set local_code_index_offered true │
98 └──────────────────────────────────────────────────────────────────┘
100NOTICE
101fi
103# Always touch done so we don't print again, regardless of state-match outcome.
104touch "$DONE_TOUCH"