fix(banner): plugin rows follow the effective profile, not user scope
The ✅ row and detect_uiux_pro_max read user-scope settings.json and the
plugin cache, so a dev project showed ui-ux-pro-max on and an audit
project hid pr-review-toolkit. list_on_plugins now resolves the effective
profile (user scope for unmanaged ids); status-reporter and the plugin
advisor read per-project state from it.
This commit is contained in:
1 parent
9f9821eab7
commit
556d0e6ddf
6 files changed
+179
-17
No files matched your search
+30
-4
@@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
# ============================================================
|
||||
# lib/detect-plugins.sh — Single source of truth for plugin detection
|
||||
# Sourced by: session-start.sh, doctor.sh
|
||||
# Sourced by: session-start.sh, doctor.sh, agents/status-reporter.md
|
||||
#
|
||||
# Each function returns 0 (detected) or 1 (not detected).
|
||||
# No output — callers handle messaging.
|
||||
# detect_* return 0 (detected) or 1 (not detected), silently — callers
|
||||
# handle messaging. detect_plan and list_on_plugins print to stdout.
|
||||
# ============================================================
|
||||
|
||||
# --- Always-on plugins ---
|
||||
@@ -23,6 +23,30 @@ detect_superpowers() {
|
||||
}
|
||||
|
||||
|
||||
# --- Effective plugin state ---
|
||||
|
||||
list_on_plugins() {
|
||||
# Enabled plugin ids for this project and conversation, one per line:
|
||||
# the effective profile for the ids lib/profiles manages (BDR-134),
|
||||
# user-scope true for the others (LRN-005). Always returns 0.
|
||||
# shortcut: unmanaged ids read user scope only (not project/local) and
|
||||
# a skills-dir mod set in no scope (memory) is not seen, nor a mod's
|
||||
# ~/.claude/<name>.json off switch; upgrade = jq merge of the scopes +
|
||||
# plugin manifests.
|
||||
local plain="${PROFILE_PLAIN:-}" user
|
||||
[ -n "$plain" ] || plain="$(bash "$HOME/.claude/lib/profile.sh" -C "$PWD" \
|
||||
current --plain 2>/dev/null)" || plain=""
|
||||
user="$(grep -oE '"[A-Za-z0-9_-]+@[A-Za-z0-9_-]+"[[:space:]]*:[[:space:]]*true' \
|
||||
"$HOME/.claude/settings.json" 2>/dev/null)" || user=""
|
||||
awk -F= 'FNR == NR { if (sub(/^plugin:/, "", $1)) { m[$1] = 1
|
||||
if ($2 == "on") print $1 }; next }
|
||||
{ sub(/^"/, ""); sub(/".*$/, "") }
|
||||
$0 != "" && !($0 in m) && $0 !~ /^pack-.*@skills-dir$/' \
|
||||
<(printf '%s\n' "$plain") <(printf '%s\n' "$user")
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
# --- Toggle plugins ---
|
||||
|
||||
detect_gstack() {
|
||||
@@ -47,8 +71,10 @@ detect_plugin_dev() {
|
||||
}
|
||||
|
||||
detect_uiux_pro_max() {
|
||||
# installed (cache) AND enabled for this project (here-string: no pipe)
|
||||
local cache_dir="$HOME/.claude/plugins/cache"
|
||||
[ -d "$cache_dir" ] && compgen -G "$cache_dir"/*ui-ux-pro-max* &>/dev/null
|
||||
[ -d "$cache_dir" ] && compgen -G "$cache_dir"/*ui-ux-pro-max* &>/dev/null \
|
||||
&& grep -q '^ui-ux-pro-max@' <<<"$(list_on_plugins)"
|
||||
}
|
||||
|
||||
detect_context7() {
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env bash
|
||||
# lib/tests/session-banner.test.sh — the banner and detect_uiux_pro_max
|
||||
# follow the project's effective profile, not user scope / the plugin cache
|
||||
# (BDR-134). Fake HOME and projects under mktemp -d; the real ~/.claude is
|
||||
# never linked or touched (only lib/ and skills/ of the repo are linked).
|
||||
set -u
|
||||
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
||||
SS="$ROOT/hooks/session-start.sh"
|
||||
DP="$ROOT/lib/detect-plugins.sh"
|
||||
WORK="$(mktemp -d)" || exit 1; trap 'rm -rf "$WORK"' EXIT
|
||||
export SESSION_START_OFFLINE=1
|
||||
pass=0; fail=0
|
||||
check() { if [ "$2" = "$3" ]; then pass=$((pass+1)); else fail=$((fail+1));
|
||||
printf 'FAIL %s: got[%s] want[%s]\n' "$1" "$2" "$3"; fi; }
|
||||
# has <text> <word>: 1 when the text contains the word, else 0
|
||||
has() { case "$1" in *"$2"*) echo 1 ;; *) echo 0 ;; esac; }
|
||||
|
||||
# shellcheck source=lib/tests/claude-stub.sh
|
||||
. "$ROOT/lib/tests/claude-stub.sh" || exit 1
|
||||
claude_stub_install "$WORK"
|
||||
# rtk pinned present, whatever the machine has
|
||||
printf '#!/bin/sh\nexit 0\n' >"$WORK/stub/rtk" || exit 1
|
||||
chmod +x "$WORK/stub/rtk" || exit 1
|
||||
|
||||
UIUX='"ui-ux-pro-max@ui-ux-pro-max-skill":true'
|
||||
SEC='"security-guidance@claude-code-plugins":true'
|
||||
USER_ALL='{"enabledPlugins":{'"$UIUX,$SEC"',"foo-extra@somewhere":true,
|
||||
"pack-seo@skills-dir":true}}'
|
||||
USER_MANAGED='{"enabledPlugins":{'"$UIUX,$SEC"'}}'
|
||||
|
||||
# mkhome <name> <cache:1|0> <lib:1|0> <settings>: fake HOME, two links only
|
||||
mkhome() {
|
||||
local h="$WORK/$1"
|
||||
mkdir -p "$h/.claude" || exit 1
|
||||
if [ -L "$h/.claude/settings.json" ] || [ -L "$h/.claude/plugins" ]; then
|
||||
echo "fixture path is a symlink: $h" >&2; exit 1
|
||||
fi
|
||||
printf '%s\n' "$4" >"$h/.claude/settings.json" || exit 1
|
||||
[ "$2" = 1 ] && mkdir -p \
|
||||
"$h/.claude/plugins/cache/ui-ux-pro-max-skill/ui-ux-pro-max"
|
||||
if [ "$3" = 1 ]; then
|
||||
ln -s "$ROOT/lib" "$h/.claude/lib" || exit 1
|
||||
[ -L "$h/.claude/lib" ] || exit 1
|
||||
fi
|
||||
ln -s "$ROOT/skills" "$h/.claude/skills" || exit 1
|
||||
[ -L "$h/.claude/skills" ] || exit 1
|
||||
}
|
||||
mkhome h1 1 1 "$USER_ALL"
|
||||
mkhome h2 0 1 "$USER_ALL"
|
||||
mkhome h3 1 0 "$USER_ALL"
|
||||
mkhome h4 1 1 "$USER_MANAGED"
|
||||
|
||||
mkdir -p "$WORK/pdev/.claude" "$WORK/paudit/.claude" "$WORK/pfull/.claude" \
|
||||
|| exit 1
|
||||
cp "$ROOT/lib/profiles/dev.json" "$WORK/pdev/.claude/settings.local.json"
|
||||
cp "$ROOT/lib/profiles/audit.json" "$WORK/paudit/.claude/settings.local.json"
|
||||
|
||||
# banner <home> <proj>: the hook output
|
||||
banner() {
|
||||
(cd "$WORK/$2" && HOME="$WORK/$1" bash "$SS" </dev/null 2>/dev/null)
|
||||
}
|
||||
# row <marker> <text>: the marker line plus its continuation line
|
||||
row() {
|
||||
awk -v m="$1" 'f && /^│ {13}/ { print; f = 0; next } { f = 0 }
|
||||
index($0, m) { print; f = 1 }' <<<"$2"
|
||||
}
|
||||
|
||||
# SB1: dev project, user scope has ui-ux-pro-max on
|
||||
out="$(banner h1 pdev)"
|
||||
on="$(row '🟢 ON' "$out")"; off="$(row '⚫ OFF' "$out")"
|
||||
ok="$(row '✅ ON' "$out")"
|
||||
check SB1-toggle-on-no-uiux "$(has "$on" ui-ux-pro-max)" 0
|
||||
check SB1-toggle-off-uiux "$(has "$off" ui-ux-pro-max)" 1
|
||||
for w in rtk model-router security-guidance foo-extra; do
|
||||
check "SB1-onrow-$w" "$(has "$ok" "$w")" 1
|
||||
done
|
||||
for w in pr-review-toolkit pack-seo; do
|
||||
check "SB1-onrow-no-$w" "$(has "$ok" "$w")" 0
|
||||
done
|
||||
|
||||
# SB2: audit project shows pr-review-toolkit, hides ui-ux-pro-max
|
||||
out="$(banner h1 paudit)"
|
||||
check SB2-onrow-pr-review "$(has "$(row '✅ ON' "$out")" pr-review-toolkit)" 1
|
||||
check SB2-toggle-on-no-uiux "$(has "$(row '🟢 ON' "$out")" ui-ux-pro-max)" 0
|
||||
|
||||
# SB3: no profile (full): ui-ux-pro-max on, pr-review-toolkit absent
|
||||
out="$(banner h1 pfull)"
|
||||
check SB3-toggle-on-uiux "$(has "$(row '🟢 ON' "$out")" ui-ux-pro-max)" 1
|
||||
ok="$(row '✅ ON' "$out")"
|
||||
check SB3-onrow-no-pr-review "$(has "$ok" pr-review-toolkit)" 0
|
||||
|
||||
# uiux <home> <proj>: exit status of detect_uiux_pro_max, PROFILE_PLAIN unset
|
||||
uiux() {
|
||||
(cd "$WORK/$2" && unset PROFILE_PLAIN && HOME="$WORK/$1" bash -c \
|
||||
". '$DP'; detect_uiux_pro_max; echo \$?")
|
||||
}
|
||||
# SB4: follows the profile, still needs the cache
|
||||
check SB4-dev-off "$(uiux h1 pdev)" 1
|
||||
check SB4-full-on "$(uiux h1 pfull)" 0
|
||||
check SB4-not-installed "$(uiux h2 pfull)" 1
|
||||
|
||||
# SB5: profile.sh unreachable, user-scope fallback
|
||||
check SB5-uiux-fallback "$(uiux h3 pdev)" 0
|
||||
lst="$(cd "$WORK/pdev" && unset PROFILE_PLAIN && HOME="$WORK/h3" bash -c \
|
||||
". '$DP'; list_on_plugins")"
|
||||
for w in security-guidance@claude-code-plugins \
|
||||
ui-ux-pro-max@ui-ux-pro-max-skill foo-extra@somewhere; do
|
||||
check "SB5-list-$w" "$(has "$lst" "$w")" 1
|
||||
done
|
||||
check SB5-list-no-pack "$(has "$lst" pack-seo@skills-dir)" 0
|
||||
|
||||
# SB6: survives set -euo pipefail (doctor.sh options)
|
||||
res="$(cd "$WORK/pfull" && unset PROFILE_PLAIN && HOME="$WORK/h4" bash -c \
|
||||
"set -euo pipefail; . '$DP'; detect_uiux_pro_max; echo u\$?;
|
||||
list_on_plugins >/dev/null; echo l\$?; echo alive" | tr '\n' ' ')"
|
||||
check SB6-pipefail "$res" 'u0 l0 alive '
|
||||
|
||||
# SB7: empty list_on_plugins (no profile.sh, no user id) leaves no empty
|
||||
# element in the ✅ row
|
||||
mkhome h5 0 0 '{"enabledPlugins":{"x@y":false}}'
|
||||
out="$(banner h5 pfull)"
|
||||
ao="$(row '✅ ON' "$out")"; ao="${ao#*: }"; ao="${ao%│}"
|
||||
ao="${ao%"${ao##*[![:space:]]}"}"
|
||||
check SB7-empty-list-rtk-only "$ao" rtk
|
||||
|
||||
# SB8: no hook run of this suite called the claude CLI (BLK-043)
|
||||
check SB8-no-claude-calls "$(claude_stub_calls)" 0
|
||||
|
||||
printf 'session-banner: %d passed, %d failed\n' "$pass" "$fail"
|
||||
[ "$fail" -eq 0 ]
|
||||
Reference in new issue
Block a user