diff --git a/bin/gstack-config b/bin/gstack-config index e99a940b..1147addd 100755 --- a/bin/gstack-config +++ b/bin/gstack-config @@ -23,7 +23,9 @@ case "${1:-}" in VALUE="${3:?Usage: gstack-config set }" mkdir -p "$STATE_DIR" if grep -qE "^${KEY}:" "$CONFIG_FILE" 2>/dev/null; then - sed -i '' "s/^${KEY}:.*/${KEY}: ${VALUE}/" "$CONFIG_FILE" + # Portable in-place edit (BSD sed uses -i '', GNU sed uses -i without arg) + _tmpfile="$(mktemp "${CONFIG_FILE}.XXXXXX")" + sed "s/^${KEY}:.*/${KEY}: ${VALUE}/" "$CONFIG_FILE" > "$_tmpfile" && mv "$_tmpfile" "$CONFIG_FILE" else echo "${KEY}: ${VALUE}" >> "$CONFIG_FILE" fi diff --git a/scripts/resolvers/preamble.ts b/scripts/resolvers/preamble.ts index fe0ba77e..4e5092f8 100644 --- a/scripts/resolvers/preamble.ts +++ b/scripts/resolvers/preamble.ts @@ -24,8 +24,10 @@ _PROACTIVE=$(${ctx.paths.binDir}/gstack-config get proactive 2>/dev/null || echo _PROACTIVE_PROMPTED=$([ -f ~/.gstack/.proactive-prompted ] && echo "yes" || echo "no") _BRANCH=$(git branch --show-current 2>/dev/null || echo "unknown") echo "BRANCH: $_BRANCH" +_SKILL_PREFIX=$(${ctx.paths.binDir}/gstack-config get skill_prefix 2>/dev/null || echo "false") echo "PROACTIVE: $_PROACTIVE" echo "PROACTIVE_PROMPTED: $_PROACTIVE_PROMPTED" +echo "SKILL_PREFIX: $_SKILL_PREFIX" source <(${ctx.paths.binDir}/gstack-repo-mode 2>/dev/null) || true REPO_MODE=\${REPO_MODE:-unknown} echo "REPO_MODE: $REPO_MODE" @@ -51,6 +53,11 @@ types (e.g., /qa, /ship). If you would have auto-invoked a skill, instead briefl "I think /skillname might help here — want me to run it?" and wait for confirmation. The user opted out of proactive behavior. +If \`SKILL_PREFIX\` is \`"true"\`, the user has namespaced skill names. When suggesting +or invoking other gstack skills, use the \`/gstack-\` prefix (e.g., \`/gstack-qa\` instead +of \`/qa\`, \`/gstack-ship\` instead of \`/ship\`). Disk paths are unaffected — always use +\`${ctx.paths.skillRoot}/[skill-name]/SKILL.md\` for reading skill files. + If output shows \`UPGRADE_AVAILABLE \`: read \`${ctx.paths.skillRoot}/gstack-upgrade/SKILL.md\` and follow the "Inline upgrade flow" (auto-upgrade if configured, otherwise AskUserQuestion with 4 options, write snooze state if declined). If \`JUST_UPGRADED \`: tell user "Running gstack v{to} (just updated!)" and continue.`; } diff --git a/setup b/setup index 71306839..995833ae 100755 --- a/setup +++ b/setup @@ -24,12 +24,14 @@ esac HOST="claude" LOCAL_INSTALL=0 SKILL_PREFIX=1 +SKILL_PREFIX_FLAG=0 while [ $# -gt 0 ]; do case "$1" in --host) [ -z "$2" ] && echo "Missing value for --host (expected claude, codex, kiro, or auto)" >&2 && exit 1; HOST="$2"; shift 2 ;; --host=*) HOST="${1#--host=}"; shift ;; --local) LOCAL_INSTALL=1; shift ;; - --no-prefix) SKILL_PREFIX=0; shift ;; + --prefix) SKILL_PREFIX=1; SKILL_PREFIX_FLAG=1; shift ;; + --no-prefix) SKILL_PREFIX=0; SKILL_PREFIX_FLAG=1; shift ;; *) shift ;; esac done @@ -39,6 +41,44 @@ case "$HOST" in *) echo "Unknown --host value: $HOST (expected claude, codex, kiro, or auto)" >&2; exit 1 ;; esac +# ─── Resolve skill prefix preference ───────────────────────── +# Priority: CLI flag > saved config > interactive prompt (or flat default for non-TTY) +GSTACK_CONFIG="$SOURCE_GSTACK_DIR/bin/gstack-config" +if [ "$SKILL_PREFIX_FLAG" -eq 0 ]; then + _saved_prefix="$("$GSTACK_CONFIG" get skill_prefix 2>/dev/null || true)" + if [ "$_saved_prefix" = "true" ]; then + SKILL_PREFIX=1 + elif [ "$_saved_prefix" = "false" ]; then + SKILL_PREFIX=0 + else + # No saved preference — prompt interactively (or default flat for non-TTY) + if [ -t 0 ]; then + echo "" + echo "Skill naming: how should gstack skills appear?" + echo "" + echo " 1) Short names: /qa, /ship, /review" + echo " Recommended. Clean and fast to type." + echo "" + echo " 2) Namespaced: /gstack-qa, /gstack-ship, /gstack-review" + echo " Use this if you run other skill packs alongside gstack to avoid conflicts." + echo "" + printf "Choice [1/2] (default: 1): " + read -r _prefix_choice /dev/null || _prefix_choice="" + case "$_prefix_choice" in + 2) SKILL_PREFIX=1 ;; + *) SKILL_PREFIX=0 ;; + esac + else + SKILL_PREFIX=0 + fi + # Save the choice for future runs + "$GSTACK_CONFIG" set skill_prefix "$([ "$SKILL_PREFIX" -eq 1 ] && echo true || echo false)" 2>/dev/null || true + fi +else + # Flag was passed explicitly — persist the choice + "$GSTACK_CONFIG" set skill_prefix "$([ "$SKILL_PREFIX" -eq 1 ] && echo true || echo false)" 2>/dev/null || true +fi + # --local: install to .claude/skills/ in the current working directory if [ "$LOCAL_INSTALL" -eq 1 ]; then if [ "$HOST" = "codex" ]; then @@ -266,6 +306,38 @@ cleanup_old_claude_symlinks() { fi } +# ─── Helper: remove old prefixed Claude skill symlinks ──────────────────────── +# Reverse migration: when switching from gstack- prefixed names to flat names, +# clean up stale gstack-* symlinks that point into the gstack directory. +cleanup_prefixed_claude_symlinks() { + local gstack_dir="$1" + local skills_dir="$2" + local removed=() + for skill_dir in "$gstack_dir"/*/; do + if [ -f "$skill_dir/SKILL.md" ]; then + skill_name="$(basename "$skill_dir")" + [ "$skill_name" = "node_modules" ] && continue + # Only clean up prefixed symlinks for dirs that AREN'T already prefixed + # (e.g., remove gstack-qa but NOT gstack-upgrade which is the real dir name) + case "$skill_name" in gstack-*) continue ;; esac + prefixed_target="$skills_dir/gstack-$skill_name" + # Only remove if it's a symlink pointing into gstack/ + if [ -L "$prefixed_target" ]; then + link_dest="$(readlink "$prefixed_target" 2>/dev/null || true)" + case "$link_dest" in + gstack/*|*/gstack/*) + rm -f "$prefixed_target" + removed+=("gstack-$skill_name") + ;; + esac + fi + fi + done + if [ ${#removed[@]} -gt 0 ]; then + echo " cleaned up prefixed symlinks: ${removed[*]}" + fi +} + # ─── Helper: link generated Codex skills into a skills parent directory ── # Installs from .agents/skills/gstack-* (the generated Codex-format skills) # instead of source dirs (which have Claude paths). @@ -393,9 +465,11 @@ fi if [ "$INSTALL_CLAUDE" -eq 1 ]; then if [ "$SKILLS_BASENAME" = "skills" ]; then - # Clean up old unprefixed symlinks from previous installs + # Clean up stale symlinks from the opposite prefix mode if [ "$SKILL_PREFIX" -eq 1 ]; then cleanup_old_claude_symlinks "$SOURCE_GSTACK_DIR" "$INSTALL_SKILLS_DIR" + else + cleanup_prefixed_claude_symlinks "$SOURCE_GSTACK_DIR" "$INSTALL_SKILLS_DIR" fi link_claude_skill_dirs "$SOURCE_GSTACK_DIR" "$INSTALL_SKILLS_DIR" if [ "$LOCAL_INSTALL" -eq 1 ]; then @@ -497,8 +571,8 @@ if [ "$INSTALL_CODEX" -eq 1 ]; then fi # 8. First-time welcome + legacy cleanup -if [ ! -d "$HOME/.gstack" ]; then - mkdir -p "$HOME/.gstack" +if [ ! -f "$HOME/.gstack/.welcome-seen" ]; then echo " Welcome! Run /gstack-upgrade anytime to stay current." + touch "$HOME/.gstack/.welcome-seen" fi rm -f /tmp/gstack-latest-version