mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-02 03:35:09 +02:00
feat: smart update check with auto-upgrade, snooze backoff, config CLI (v0.3.9) (#62)
* feat: add bin/gstack-config CLI for reading/writing ~/.gstack/config.yaml Simple get/set/list interface for persistent gstack configuration. Used by update-check and upgrade skill for auto_upgrade and update_check settings. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: smart update check with 12h cache, snooze backoff, config disable - Reduce cache TTL from 24h to 12h for faster update detection - Add exponential snooze backoff: 24h → 48h → 1 week (resets on new version) - Add update_check: false config option to disable checks entirely - Clear snooze file on just-upgraded - 14 new tests covering snooze levels, expiry, corruption, and config paths Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: upgrade skill with auto-upgrade, 4-option prompt, vendored sync - Auto-upgrade mode via config or GSTACK_AUTO_UPGRADE=1 env var - 4-option AskUserQuestion: upgrade once, always, not now, never - Step 4.5: sync local vendored copy after upgrading primary install - Snooze write with escalating backoff on "Not now" - Update preamble text in gen-skill-docs for new upgrade flow - Regenerate all SKILL.md files Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: simplify upgrade instructions, move auto-upgrade to completed README now points to /gstack-upgrade instead of long paste commands. Auto-upgrade TODO moved to Completed section (v0.3.8). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: bump version and changelog (v0.3.9) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Executable
+38
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
# gstack-config — read/write ~/.gstack/config.yaml
|
||||
#
|
||||
# Usage:
|
||||
# gstack-config get <key> — read a config value
|
||||
# gstack-config set <key> <value> — write a config value
|
||||
# gstack-config list — show all config
|
||||
#
|
||||
# Env overrides (for testing):
|
||||
# GSTACK_STATE_DIR — override ~/.gstack state directory
|
||||
set -euo pipefail
|
||||
|
||||
STATE_DIR="${GSTACK_STATE_DIR:-$HOME/.gstack}"
|
||||
CONFIG_FILE="$STATE_DIR/config.yaml"
|
||||
|
||||
case "${1:-}" in
|
||||
get)
|
||||
KEY="${2:?Usage: gstack-config get <key>}"
|
||||
grep -E "^${KEY}:" "$CONFIG_FILE" 2>/dev/null | tail -1 | awk '{print $2}' | tr -d '[:space:]' || true
|
||||
;;
|
||||
set)
|
||||
KEY="${2:?Usage: gstack-config set <key> <value>}"
|
||||
VALUE="${3:?Usage: gstack-config set <key> <value>}"
|
||||
mkdir -p "$STATE_DIR"
|
||||
if grep -qE "^${KEY}:" "$CONFIG_FILE" 2>/dev/null; then
|
||||
sed -i '' "s/^${KEY}:.*/${KEY}: ${VALUE}/" "$CONFIG_FILE"
|
||||
else
|
||||
echo "${KEY}: ${VALUE}" >> "$CONFIG_FILE"
|
||||
fi
|
||||
;;
|
||||
list)
|
||||
cat "$CONFIG_FILE" 2>/dev/null || true
|
||||
;;
|
||||
*)
|
||||
echo "Usage: gstack-config {get|set|list} [key] [value]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
+69
-5
@@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
# gstack-update-check — daily version check for all skills.
|
||||
# gstack-update-check — periodic version check for all skills.
|
||||
#
|
||||
# Output (one line, or nothing):
|
||||
# JUST_UPGRADED <old> <new> — marker found from recent upgrade
|
||||
# UPGRADE_AVAILABLE <old> <new> — remote VERSION differs from local
|
||||
# (nothing) — up to date or check skipped
|
||||
# (nothing) — up to date, snoozed, disabled, or check skipped
|
||||
#
|
||||
# Env overrides (for testing):
|
||||
# GSTACK_DIR — override auto-detected gstack root
|
||||
@@ -16,9 +16,65 @@ GSTACK_DIR="${GSTACK_DIR:-$(cd "$(dirname "$0")/.." && pwd)}"
|
||||
STATE_DIR="${GSTACK_STATE_DIR:-$HOME/.gstack}"
|
||||
CACHE_FILE="$STATE_DIR/last-update-check"
|
||||
MARKER_FILE="$STATE_DIR/just-upgraded-from"
|
||||
SNOOZE_FILE="$STATE_DIR/update-snoozed"
|
||||
VERSION_FILE="$GSTACK_DIR/VERSION"
|
||||
REMOTE_URL="${GSTACK_REMOTE_URL:-https://raw.githubusercontent.com/garrytan/gstack/main/VERSION}"
|
||||
|
||||
# ─── Step 0: Check if updates are disabled ────────────────────
|
||||
_UC=$("$GSTACK_DIR/bin/gstack-config" get update_check 2>/dev/null || true)
|
||||
if [ "$_UC" = "false" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ─── Snooze helper ──────────────────────────────────────────
|
||||
# check_snooze <remote_version>
|
||||
# Returns 0 if snoozed (should stay quiet), 1 if not snoozed (should output).
|
||||
#
|
||||
# Snooze file format: <version> <level> <epoch>
|
||||
# Level durations: 1=24h, 2=48h, 3+=7d
|
||||
# New version (version mismatch) resets snooze.
|
||||
check_snooze() {
|
||||
local remote_ver="$1"
|
||||
if [ ! -f "$SNOOZE_FILE" ]; then
|
||||
return 1 # no snooze file → not snoozed
|
||||
fi
|
||||
local snoozed_ver snoozed_level snoozed_epoch
|
||||
snoozed_ver="$(awk '{print $1}' "$SNOOZE_FILE" 2>/dev/null || true)"
|
||||
snoozed_level="$(awk '{print $2}' "$SNOOZE_FILE" 2>/dev/null || true)"
|
||||
snoozed_epoch="$(awk '{print $3}' "$SNOOZE_FILE" 2>/dev/null || true)"
|
||||
|
||||
# Validate: all three fields must be non-empty
|
||||
if [ -z "$snoozed_ver" ] || [ -z "$snoozed_level" ] || [ -z "$snoozed_epoch" ]; then
|
||||
return 1 # corrupt file → not snoozed
|
||||
fi
|
||||
|
||||
# Validate: level and epoch must be integers
|
||||
case "$snoozed_level" in *[!0-9]*) return 1 ;; esac
|
||||
case "$snoozed_epoch" in *[!0-9]*) return 1 ;; esac
|
||||
|
||||
# New version dropped? Ignore snooze.
|
||||
if [ "$snoozed_ver" != "$remote_ver" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Compute snooze duration based on level
|
||||
local duration
|
||||
case "$snoozed_level" in
|
||||
1) duration=86400 ;; # 24 hours
|
||||
2) duration=172800 ;; # 48 hours
|
||||
*) duration=604800 ;; # 7 days (level 3+)
|
||||
esac
|
||||
|
||||
local now
|
||||
now="$(date +%s)"
|
||||
local expires=$(( snoozed_epoch + duration ))
|
||||
if [ "$now" -lt "$expires" ]; then
|
||||
return 0 # still snoozed
|
||||
fi
|
||||
|
||||
return 1 # snooze expired
|
||||
}
|
||||
|
||||
# ─── Step 1: Read local version ──────────────────────────────
|
||||
LOCAL=""
|
||||
if [ -f "$VERSION_FILE" ]; then
|
||||
@@ -32,6 +88,7 @@ fi
|
||||
if [ -f "$MARKER_FILE" ]; then
|
||||
OLD="$(cat "$MARKER_FILE" 2>/dev/null | tr -d '[:space:]')"
|
||||
rm -f "$MARKER_FILE"
|
||||
rm -f "$SNOOZE_FILE"
|
||||
mkdir -p "$STATE_DIR"
|
||||
echo "UP_TO_DATE $LOCAL" > "$CACHE_FILE"
|
||||
if [ -n "$OLD" ]; then
|
||||
@@ -40,10 +97,10 @@ if [ -f "$MARKER_FILE" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ─── Step 3: Check cache freshness (24h = 1440 min) ──────────
|
||||
# ─── Step 3: Check cache freshness (12h = 720 min) ──────────
|
||||
if [ -f "$CACHE_FILE" ]; then
|
||||
# Cache is fresh if modified within 1440 minutes
|
||||
STALE=$(find "$CACHE_FILE" -mmin +1440 2>/dev/null || true)
|
||||
# Cache is fresh if modified within 720 minutes
|
||||
STALE=$(find "$CACHE_FILE" -mmin +720 2>/dev/null || true)
|
||||
if [ -z "$STALE" ]; then
|
||||
# Cache is fresh — read it
|
||||
CACHED="$(cat "$CACHE_FILE" 2>/dev/null || true)"
|
||||
@@ -60,6 +117,10 @@ if [ -f "$CACHE_FILE" ]; then
|
||||
# Verify local version still matches cached old version
|
||||
CACHED_OLD="$(echo "$CACHED" | awk '{print $2}')"
|
||||
if [ "$CACHED_OLD" = "$LOCAL" ]; then
|
||||
CACHED_NEW="$(echo "$CACHED" | awk '{print $3}')"
|
||||
if check_snooze "$CACHED_NEW"; then
|
||||
exit 0 # snoozed — stay quiet
|
||||
fi
|
||||
echo "$CACHED"
|
||||
exit 0
|
||||
fi
|
||||
@@ -90,4 +151,7 @@ fi
|
||||
|
||||
# Versions differ — upgrade available
|
||||
echo "UPGRADE_AVAILABLE $LOCAL $REMOTE" > "$CACHE_FILE"
|
||||
if check_snooze "$REMOTE"; then
|
||||
exit 0 # snoozed — stay quiet
|
||||
fi
|
||||
echo "UPGRADE_AVAILABLE $LOCAL $REMOTE"
|
||||
|
||||
Reference in New Issue
Block a user