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

v1.58.0.0.sh

65 lines · gstack-upgrade/migrations/v1.58.0.0.sh at 3f79d81

1#!/usr/bin/env bash
2# Migration: v1.58.0.0 — register the PreToolUse AskUserQuestion hook for
3# existing Conductor installs.
4#
5# Why a migration: v1.58 makes the PreToolUse question-preference-hook also
6# deny the flaky Conductor AskUserQuestion and redirect to a prose decision
7# brief. But setup's hook-install block skips silently in non-interactive
8# (conductor/CI) setups, and existing users who previously declined plan-tune
9# hooks would never pick up the new Conductor backstop. This re-registers the
10# hook for Conductor users so layer 3 actually deploys.
12# Affected: users who run gstack inside Conductor and don't already have the
13# PreToolUse hook installed.
15# Scope guard: only acts inside a Conductor session (CONDUCTOR_* present) and
16# never overrides an explicit `plan_tune_hooks` opt-out.
18# Idempotent: gstack-settings-hook dedupes by (event, matcher, source), and a
19# .done touchfile gates re-runs.
21set -u
23_gstack_migration_dir="${BASH_SOURCE[0]//\\//}"; _gstack_migration_dir="${_gstack_migration_dir%/*}"
24. "${_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; }
25gstack_state_root_select; GSTACK_HOME="$_gstack_sr_root"
26MIGRATION_DIR="${GSTACK_HOME}/.migrations"
27DONE="${MIGRATION_DIR}/v1.58.0.0.done"
28mkdir -p "${MIGRATION_DIR}" 2>/dev/null || true
29[ -f "${DONE}" ] && exit 0
31# Only relevant inside Conductor — the prose-default behavior is Conductor-scoped.
32if [ -z "${CONDUCTOR_WORKSPACE_PATH:-}" ] && [ -z "${CONDUCTOR_PORT:-}" ]; then
33 touch "${DONE}"
34 exit 0
35fi
37SCRIPT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
38SETTINGS_HOOK="${SCRIPT_DIR}/bin/gstack-settings-hook"
39PREF_HOOK="${SCRIPT_DIR}/hosts/claude/hooks/question-preference-hook"
40CONFIG_BIN="${SCRIPT_DIR}/bin/gstack-config"
42# Respect an explicit opt-out — don't force a hook on a user who said no.
43_PT=$("${CONFIG_BIN}" get plan_tune_hooks 2>/dev/null || echo "")
44_PT=$(printf '%s' "${_PT}" | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')
45case "${_PT}" in
46 n|no|false|skip|off|0)
47 echo " [v1.58.0.0] plan_tune_hooks opted out — leaving Conductor on guidance-only prose." >&2
48 touch "${DONE}"
49 exit 0
50 ;;
51esac
53if [ -x "${SETTINGS_HOOK}" ] && [ -x "${PREF_HOOK}" ]; then
54 "${SETTINGS_HOOK}" add-event \
55 --event PreToolUse \
56 --matcher '(AskUserQuestion|mcp__.*__AskUserQuestion)' \
57 --command "${PREF_HOOK}" \
58 --source plan-tune-cathedral \
59 --timeout 5 2>/dev/null \
60 && echo " [v1.58.0.0] Conductor AskUserQuestion prose hook registered (PreToolUse)." >&2 \
61 || echo " [v1.58.0.0] WARN: could not register the PreToolUse hook; run ./setup --plan-tune-hooks." >&2
62fi
64touch "${DONE}"
65exit 0