11 KiB
FIX — banner-effective-profile (/bugfix G1+G4, 2026-11-10) — r3 after two challenge rounds
Source: .claude/audits/BUGS-FOUND.md entries G1 (session-start banner) and G4 (status-reporter, plugin-probe).
Diagnosis
Symptom: the session banner and two agents report user-scope / installed plugin state as the project's active state.
lib/detect-plugins.shdetect_uiux_pro_maxonly tests the plugin cache: installed = on. A project whose effective profile disables it (dev, minimal, seo, qa, audit) still showsui-ux-pro-maxin the 🟢 ON row.hooks/session-start.sh✅ ON row (≈:200-219) greps"<name>@<mkt>": truein$HOME/.claude/settings.json(user scope). A project profile that enablespr-review-toolkit(max, audit) is not shown; one that disables a user-enabled plugin still shows it.PROFILE_PLAIN(session-start ≈:98-100, oneprofile.sh -C "$PWD" current --plainrun, exported) already holds the effective state:pack-*=on|offlines andplugin:<id>=on|offlines for every id managed by lib/profiles/*.json (one shared key set of 15 ids; 6 non-pack: model-router@skills-dir, security-guidance@claude-code-plugins, ui-ux-pro-max@ui-ux-pro-max-skill, pr-review-toolkit@claude-code-plugins, example-skills@anthropic-agent-skills, brightdata-plugin@synced).detect_gstackalready reads it.- G4:
agents/status-reporter.md:23"Active plugins (from session-start detection)" and :35 "Check~/.claude/plugins/cachefor active marketplace plugins" (cache = installed, not active); :181 error row ties ON to the cache.agents/plugin-probe.md:22labelsclaude plugin list"(ids, enabled state)" and the PROBE REPORTPLUGINSfield (:69) carries it raw; plugin-advisor (ACTIVE:block, plugin-advisor.md:98) has no rule saying which field holds per-project state, so it can read PLUGINS as active. Evidence: fake HOME (lib + skills symlinked, cache dir, user settings ui-ux-pro-max true) + project settings.local.json = lib/profiles/dev.json →profile.sh current --plainprintsplugin:ui-ux-pro-max@ui-ux-pro-max-skill=off, banner prints🟢 ON : gstack ui-ux-pro-max context7 graphify. Blast radius: doctor.sh:528 callsdetect_uiux_pro_maxfor its passive-cost sum (repo cwd; after the fix it follows the cwd profile, intended; constants are G2). No other caller.
Rule (r3, after round 2: doctor pipefail BLOCKER, scope trimmed)
ENABLED for this project and conversation = plugin:<id>=on in the effective profile for the ids lib/profiles manages (BDR-134); for an id the profile does not list, "<id>": true in user-scope $HOME/.claude/settings.json (today's behavior, LRN-005); pack-*@skills-dir ids are never plugins here. Profile empty (profile.sh failed) → every id falls to the user-scope rule.
No new install check: the ✅ row never had one; detect_uiux_pro_max keeps its existing cache glob AND adds ENABLED.
Round-2 findings deliberately NOT taken (named in the shortcut comment, deferred to a later run): a mod's per-machine off switch (~/.claude/model-router.json enabled false still shows model-router); unmanaged skills-dir mods absent from every scope (memory@skills-dir, pre-existing omission, not a regression); project/local scope for unmanaged ids; install checks for the synced marketplace and for local-scope installs (moot without an install check on the ✅ row).
Fix plan
lib/detect-plugins.sh:- header lines 6-7:
detect_*return 0/1 silently;detect_planandlist_on_pluginsprint to stdout. - new function
list_on_pluginsabove# --- Toggle plugins ---(or in a short "Effective plugin state" block), pipefail-safe, alwaysreturn 0, no pipeline whose status matters, set difference in awk (nogrep -fon a possibly empty file):
(printf always emits at least one line, so FNR == NR stays a valid first-file test even whenlist_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 }plainis empty. Executor may tidy, keeping: awk set difference, explicit return 0, no pipe into the status.)detect_uiux_pro_max: keep the cache-glob test, then&& grep -q '^ui-ux-pro-max@' <<<"$(list_on_plugins)"(here-string, not a pipe), one comment line (installed AND enabled for this project).
- header lines 6-7:
hooks/session-start.sh✅ ON row: the while-loop readsdone < <(sed 's/@.*//' <<<"$(list_on_plugins)")instead of the user-settings grep; toggle-owned exclusion unchanged; rewrite the comment above it (effective profile for managed ids, user scope for the others, same function as detect_uiux_pro_max and /status). User decision 2026-11-10:model-routershown; real order on a default project:rtk model-router security-guidance(profile lines sort by id). Empty lines skipped.agents/status-reporter.md:- PHASE 1 bash block: replace the :23 comment; add (no
bash -c: settings.json asks on it). "$HOME/.claude/lib/detect-plugins.sh" && list_on_plugins || echo "plugins-unavailable"andbash "$HOME/.claude/lib/profile.sh" -C "$PWD" current --plain 2>/dev/null | grep -E '^(profile|pack-[a-z0-9-]+)=' || echo "profile-unavailable". - :35 →
~/.claude/plugins/cache= installed, not active;Plugins ON:= rtk (if present) + the names printed bylist_on_plugins(part before@) + thepack-*=onpacks. - Error table :181 → cache unreadable: no effect on
Plugins ON:;profile-unavailable→Plugins ON:fromlist_on_plugins(user-scope fallback) with suffix(profile.sh unavailable: user scope);plugins-unavailable→Plugins ON: unknown (detect-plugins.sh unavailable). - Passive-cost rule unchanged (G2 separate).
- PHASE 1 bash block: replace the :23 comment; add (no
agents/plugin-probe.md: :22 comment only → "Marketplace plugins installed; the enabled column may not reflect the project profile or --settings: per-project state = PROFILE above". PROBE REPORT template unchanged (one carrier for the rule: the advisor, step 5).agents/plugin-advisor.mdINPUT section (after :22-27), one sentence: "ACTIVE:= the managed ids fromPROFILE(pack-*=on,plugin:<id>=on); an id absent from PROFILE keeps itsPLUGINSenabled state (user scope); CLIs fromCLIS.PLUGINSalone is installed state, never per-project." No output-format change (D3 untouched).- Regression test: new
lib/tests/session-banner.test.sh(Makefile SUITES glob picks it up),set -ulike its neighbours, summary linesession-banner: %d passed, %d failed(session-digest format; exit 1 on any fail). Fixtures with mkdir/printf only, never links of the real ~/.claude (no mkhome copy); normin the body:WORK=$(mktemp -d), cleanup only by thetrap 'rm -rf "$WORK"' EXITof session-digest.test.sh; it removes the two lib/skills links without following them (assert[ -L ]on both right after creating them).- fake HOME
$WORK/h1:.claude/lib→$ROOT/liband.claude/skills→$ROOT/skills(the only two symlinks); real file.claude/settings.json={"enabledPlugins":{"ui-ux-pro-max@ui-ux-pro-max-skill":true,"security-guidance@claude-code-plugins":true,"foo-extra@somewhere":true,"pack-seo@skills-dir":true}}; real dir.claude/plugins/cache/ui-ux-pro-max-skill/ui-ux-pro-max. $WORK/h2= h1 without the cache dir.$WORK/h3= h1 without the.claude/libsymlink (profile.sh unreachable).$WORK/h4= h1 with user settings holding only managed ids (ui-ux-pro-max@ui-ux-pro-max-skill,security-guidance@claude-code-pluginstrue).- Guard before writing any fixture file:
[ ! -L "$h/.claude/settings.json" ] && [ ! -L "$h/.claude/plugins" ], else exit 1. - rtk pinned: executable
rtkstub (exit 0) in the claude stub dir on PATH. claude stub (lib/tests/claude-stub.sh, BLK-043);SESSION_START_OFFLINE=1. - every fixture project has a
.claude/dir:pdev(settings.local.json = copy of$ROOT/lib/profiles/dev.json),paudit(audit.json),pfull(empty.claude/). - helper
onrow= the✅ ONline plus the next line when it is a continuation (│+ 13 spaces);toggleon=🟢 ONline plus continuation;toggleoff=⚫ OFFline plus continuation. Every assertion, positive and negative, runs over these. Cases: - SB1 dev (h1): toggleon lacks
ui-ux-pro-max, toggleoff has it; onrow hasrtk,model-router,security-guidance,foo-extra; lackspr-review-toolkit,pack-seo. - SB2 audit (h1): onrow has
pr-review-toolkit; toggleon lacksui-ux-pro-max. - SB3 full (h1): toggleon has
ui-ux-pro-max; onrow lackspr-review-toolkit. - SB4
detect_uiux_pro_maxsourced from$ROOT/lib/detect-plugins.sh, PROFILE_PLAIN unset: dev/h1 → 1; full/h1 → 0; full/h2 → 1 (not installed). - SB5 profile.sh unreachable (h3, pdev):
detect_uiux_pro_max→ 0 (user-scope true + installed);list_on_pluginsprintssecurity-guidance@claude-code-plugins,ui-ux-pro-max@ui-ux-pro-max-skill,foo-extra@somewhere, notpack-seo@skills-dir. - SB6 pipefail (h4, pfull), in a subshell with
set -euo pipefail(doctor.sh options):detect_uiux_pro_max→ 0 andlist_on_pluginsrc 0 and the subshell survives. Red before the fix: SB1 (ui-ux in 🟢), SB2 (pr-review hidden), SB4 dev/h1, SB5/SB6 (function absent).
- Bookkeeping (orchestrator): BUGS-FOUND G1 and G4 FIXED continuation lines.
Edge cases
- Profile empty (profile.sh missing/failed, no jq): user-scope view for every id; ui-ux still cache-checked.
- Id managed and user-enabled: profile wins, no duplicate.
- Profile-enabled but not installed (pr-review-toolkit on a host without it): shown in ✅ (no install check, as today for user-enabled ids); ui-ux-pro-max keeps its cache check.
pack-*@skills-dirtrue at user scope: excluded.- doctor.sh (
set -euo pipefail):detect_uiux_pro_maxandlist_on_pluginsnever return non-zero through a pipe (SB6). - Row width: line 2 of the ✅ row pads but never truncates (pre-existing, unchanged).
In-force
BDR-134 (profile = single source of truth for per-project state), LRN-005 (never hide a user-enabled plugin), BLK-043 (claude stub in hook tests), LRN-271 (make test env). Foreign-code style: keep file style. Files: 5 code/prompt + 1 new test (the advisor line is the G4 consumer side; > 5 by one, justified: one-sentence edit).