Skill Tracer
Skills › gstack › gstack-upgrade › v0.16.2.0.sh

v0.16.2.0.sh

56 lines · gstack-upgrade/migrations/v0.16.2.0.sh at 3f79d81

1#!/usr/bin/env bash
2# Migration: v0.16.2.0 — Merge per-project resource logs into builder profile
3#
4# What changed: resource dedup moved from per-project resources-shown.jsonl to
5# the global builder-profile.jsonl (single source of truth for all closing state).
6#
7# What this does: finds all per-project resources-shown.jsonl files and merges
8# their URLs into a stub builder-profile entry so existing users don't lose
9# their dedup history. Idempotent — safe to run multiple times.
11# Affected: users who ran /office-hours before this version
12set -euo pipefail
14_gstack_migration_dir="${BASH_SOURCE[0]//\\//}"; _gstack_migration_dir="${_gstack_migration_dir%/*}"
15. "${_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; }
16gstack_state_root_select; GSTACK_HOME="$_gstack_sr_root"
17PROFILE_FILE="$GSTACK_HOME/builder-profile.jsonl"
19# Find all per-project resource logs
20RESOURCE_FILES=$(find "$GSTACK_HOME/projects" -name "resources-shown.jsonl" 2>/dev/null || true)
22if [ -z "$RESOURCE_FILES" ]; then
23 # No per-project resource files exist — clean install, nothing to migrate
24 exit 0
25fi
27echo " [v0.16.2.0] Migrating per-project resource logs to builder profile..."
29# Collect all unique URLs from all per-project files
30ALL_URLS=$(echo "$RESOURCE_FILES" | while read -r f; do
31 [ -f "$f" ] && cat "$f" 2>/dev/null || true
32done | grep -o '"url":"[^"]*"' | sed 's/"url":"//;s/"//' | sort -u)
34if [ -z "$ALL_URLS" ]; then
35 exit 0
36fi
38# Check if builder-profile already has resource data (idempotency)
39if [ -f "$PROFILE_FILE" ] && grep -q "resources_shown" "$PROFILE_FILE" 2>/dev/null; then
40 # Already has resource data, check if it includes the migrated URLs
41 EXISTING_URLS=$(grep -o '"resources_shown":\[[^]]*\]' "$PROFILE_FILE" 2>/dev/null | grep -o 'https://[^"]*' | sort -u)
42 NEW_URLS=$(comm -23 <(echo "$ALL_URLS") <(echo "$EXISTING_URLS") 2>/dev/null || echo "$ALL_URLS")
43 if [ -z "$NEW_URLS" ]; then
44 # All URLs already present — nothing to do
45 exit 0
46 fi
47fi
49# Build JSON array of URLs
50URL_ARRAY=$(echo "$ALL_URLS" | awk 'BEGIN{printf "["} NR>1{printf ","} {printf "\"%s\"", $0} END{printf "]"}')
52# Append a migration stub entry to the builder profile
53mkdir -p "$GSTACK_HOME"
54echo "{\"date\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\",\"mode\":\"migration\",\"project_slug\":\"_migrated\",\"signal_count\":0,\"signals\":[],\"design_doc\":\"\",\"assignment\":\"\",\"resources_shown\":$URL_ARRAY,\"topics\":[]}" >> "$PROFILE_FILE"
56echo " [v0.16.2.0] Migrated $(echo "$ALL_URLS" | wc -l | tr -d ' ') resource URLs to builder profile."