From 9b7f44aed7994be60f5639f4efb11bdcf2227dd2 Mon Sep 17 00:00:00 2001 From: bchanot Date: Tue, 10 Nov 2026 12:44:15 +0100 Subject: [PATCH] chore(memory): G1+G4 fixed, BLK-046, LRN-274, contract and plan, journal --- .claude/audits/BUGS-FOUND.md | 2 + .claude/memory/blockers.md | 6 ++ .claude/memory/journal.md | 3 + .claude/memory/learnings.md | 5 ++ ...026-11-10-banner-effective-profile-1015.md | 28 +++++++ ...026-11-10-banner-effective-profile-1015.md | 83 +++++++++++++++++++ 6 files changed, 127 insertions(+) create mode 100644 .claude/tasks/contracts/2026-11-10-banner-effective-profile-1015.md create mode 100644 .claude/tasks/plans/2026-11-10-banner-effective-profile-1015.md diff --git a/.claude/audits/BUGS-FOUND.md b/.claude/audits/BUGS-FOUND.md index e95c6a6..2a4a452 100644 --- a/.claude/audits/BUGS-FOUND.md +++ b/.claude/audits/BUGS-FOUND.md @@ -5,8 +5,10 @@ - hooks/session-start.sh:200-217 + lib/detect-plugins.sh:49-52 (`detect_uiux_pro_max`) — the banner "ALWAYS ON" row and the ui-ux-pro-max toggle row read user-scope settings.json / plugin cache, not the effective profile (`profile.sh current --plain`, BDR-134 single source of truth): a dev or minimal project shows ui-ux-pro-max on; pr-review-toolkit on in max/audit is not shown. Severity: low (banner only). Discovered while: code-clean 2026-11-09 (phase 5 sweep). Not fixed. + FIXED 2026-11-10 (/bugfix, bugfix/banner-effective-profile): new `list_on_plugins` (lib/detect-plugins.sh) = effective profile for the ids lib/profiles manages, user-scope true for the others; the ✅ row reads it (model-router now shown, user choice) and `detect_uiux_pro_max` = cache AND enabled; pipefail-safe for doctor.sh; test lib/tests/session-banner.test.sh SB1-SB8. - hooks/session-start.sh:177-183 + agents/plugin-advisor.md:193,197,211,226,233,263 vs doctor.sh:520-526 — passive-cost constants disagree (banner/advisor: gstack 2750, ui-ux-pro-max 400, context7 200, graphify 300; doctor dropped gstack/context7/graphify 2026-09-28 as double counting, ui-ux-pro-max 670); agents/status-reporter.md:26-30 names doctor as source of truth. Severity: low (estimates). Discovered while: code-clean 2026-11-09. Not fixed. - hooks/session-start.sh:404-408 (`_digest_journal`) — greps `^- ` without skipping HTML comments; templates/memory/journal.md:19-21 holds `- ` bullets inside ``, so a template-born project prints "- journal: " in the session digest until its first journal write. Fix template and digest together. Severity: low. Discovered while: code-clean 2026-11-09 (phase 4 sweep). Not fixed. FIXED 2026-11-09 (/hotfix, bugfix/digest-journal-comment): the digest skips HTML comment blocks (opener anchored at line start, CommonMark rule; an inline ` blocks (opener anchored line start, END guard), SD18 3 checks; challenge MAJOR x2 (unanchored opener) folded; template untouched; security PASS. + +## 2026-11-10 +- 2026-11-10: /bugfix G1+G4 banner effective profile: list_on_plugins (profile managed ids, user scope rest) feeds ✅ row, detect_uiux_pro_max, /status; 2 challenge rounds (doctor pipefail BLOCKER r2), gates MET/CONFORME/PASS; 556d0e6, changelog 6cdc374. diff --git a/.claude/memory/learnings.md b/.claude/memory/learnings.md index 5fc1f47..6786df6 100644 --- a/.claude/memory/learnings.md +++ b/.claude/memory/learnings.md @@ -2016,3 +2016,8 @@ Rule: when editing a doctrine file under structure locks, grep the test's lock s - **Pattern**: `gitflow finish` purges transient `docs/superpowers/{specs,plans}` only on feature/bugfix branches (BDR-065, `_gitflow_purge_transient`). /ship-feature on a `chore/*` branch (cleanup, no new behavior per gitflow doctrine) → write the plan to `.claude/tasks/plans/--.md` (durable, allowlisted), else transient plan lands on develop. - **Context**: 2026-11-09 connector-deny cleanup via /ship-feature: writing-plans default path docs/superpowers/plans; caught by the transient-artifacts path rule before commit, plan moved. - **Future use**: ship-feature STEP 4 says `start feature`; when doctrine says chore, also move the plan path. Candidate: ship-feature/writing-plans note. + +## LRN-274 — Pipefail callers: no pipe into grep -q, capture output, awk set difference, return 0 (2026-11-10) +- **Context**: `list_on_plugins` r2 draft = brace group piped into while loop, ending on `grep -vxF -f`; `detect_uiux_pro_max` = `list_on_plugins | grep -q`. doctor.sh runs `set -euo pipefail`. Grep selecting nothing exits 1; `grep -q` early exit gives SIGPIPE 141. Under pipefail both leak: detect reads OFF though match found. Challenger ran it: `list rc=1`, `detect rc=1`. Test suites run `set -u` only, so tests stayed green. +- **Pattern**: lib function sourced by a pipefail caller: capture output into var, test with here-string (`grep -q x <<<"$(fn)"`); set difference in awk not `grep -v -f` (empty pattern file also non-portable); assignment fallbacks `|| var=""`; explicit `return 0` on printing functions. +- **Future application**: any lib/*.sh sourced by doctor.sh or another `set -euo pipefail` script; add one test case run inside a `set -euo pipefail` subshell. diff --git a/.claude/tasks/contracts/2026-11-10-banner-effective-profile-1015.md b/.claude/tasks/contracts/2026-11-10-banner-effective-profile-1015.md new file mode 100644 index 0000000..07a208c --- /dev/null +++ b/.claude/tasks/contracts/2026-11-10-banner-effective-profile-1015.md @@ -0,0 +1,28 @@ +# CONTRACT — banner-effective-profile +- date: 2026-11-10 | flow: bugfix | branch: bugfix/banner-effective-profile +- status: active + +## REQUEST (verbatim — IMMUTABLE) +G1+G4 from .claude/audits/BUGS-FOUND.md (code-clean 2026-11-09). G1: hooks/session-start.sh:200-217 banner "ALWAYS ON" row + ui-ux-pro-max toggle row, and lib/detect-plugins.sh:49-52 `detect_uiux_pro_max`, read user-scope settings.json / plugin cache, not the effective profile (`bash lib/profile.sh current --plain`, BDR-134 single source of truth): a dev or minimal project shows ui-ux-pro-max on; pr-review-toolkit on in max/audit is not shown. G4: agents/status-reporter.md:35 + agents/plugin-probe.md:22-23,69 report installed (cache) or user-scope `claude plugin list` state as "active"; the per-project state is the PROFILE line (`current --plain`). Fix: per-project effective state from profile.sh in the banner rows and detection, and agents report active per the profile, installed separately. Regression test in the existing session-start / detect-plugins test suites. Mark both BUGS-FOUND entries FIXED. make test needs GATES_TIMEOUT=600 + PATH=$HOME/.bun/bin:$PATH (LRN-271). Foreign-code style (keep file style). + +## CLARIFICATIONS +Q: once the ✅ ON row reads the effective profile, model-router (on in every profile) appears; show it? / A: show it (user, 2026-11-10) [gated] +Q: regression test location ("existing session-start / detect-plugins suites" do not exist; only session-digest.test.sh runs the hook)? / A: new lib/tests/session-banner.test.sh, same harness style (orchestrator, internal) +Q: plan revisions? / A: plan r3 after two challenge rounds: .claude/tasks/plans/2026-11-10-banner-effective-profile-1015.md is the binding FIX PLAN (orchestrator) + +## ACCEPTANCE CRITERIA +1. Symptom gone: in a project whose local profile is dev, the banner's 🟢 row omits ui-ux-pro-max; under audit the ✅ row shows pr-review-toolkit; `detect_uiux_pro_max` follows the effective profile and stays correct under `set -euo pipefail`; regression suite present and green. + CHECK: cd /home/bchanot/Documents/claude && make test suite=lib/tests/session-banner.test.sh 2>&1 | tail -1 | grep -q 'all suites green' && grep -q 'SB1' lib/tests/session-banner.test.sh && grep -q 'SB2' lib/tests/session-banner.test.sh && grep -q 'pipefail' lib/tests/session-banner.test.sh && grep -q '^list_on_plugins()' lib/detect-plugins.sh && echo SYMPTOM-GONE + EXPECT: SYMPTOM-GONE + EVIDENCE: MET exit=0 marker-found :: SYMPTOM-GONE +2. Agents report per-project state: status-reporter derives Plugins ON from `list_on_plugins` (no `bash -c`), cache = installed only; plugin-probe comment and plugin-advisor INPUT name PROFILE as the per-project source. + CHECK: cd /home/bchanot/Documents/claude && grep -q 'list_on_plugins' agents/status-reporter.md && ! grep -q 'for active marketplace plugins' agents/status-reporter.md && ! grep -q 'bash -c' agents/status-reporter.md && grep -q 'profile-unavailable' agents/status-reporter.md && grep -q 'per-project state = PROFILE' agents/plugin-probe.md && grep -q 'never per-project' agents/plugin-advisor.md && echo AGENTS-OK + EXPECT: AGENTS-OK + EVIDENCE: MET exit=0 marker-found :: AGENTS-OK +3. Build/tests green (full suite, GATES_TIMEOUT=600, bun on PATH); shellcheck at warning level clean on the touched shell files. + CHECK: cd /home/bchanot/Documents/claude && shellcheck -S warning lib/detect-plugins.sh hooks/session-start.sh lib/tests/session-banner.test.sh && make test 2>&1 | tail -1 | grep -q 'all suites green' && echo GREEN + EXPECT: GREEN + EVIDENCE: MET exit=0 marker-found :: GREEN + +## FILE SCOPE +lib/detect-plugins.sh, hooks/session-start.sh (✅ row source + comment only), agents/status-reporter.md, agents/plugin-probe.md (:22 comment only), agents/plugin-advisor.md (one INPUT sentence), lib/tests/session-banner.test.sh (new); bookkeeping (orchestrator): .claude/audits/BUGS-FOUND.md diff --git a/.claude/tasks/plans/2026-11-10-banner-effective-profile-1015.md b/.claude/tasks/plans/2026-11-10-banner-effective-profile-1015.md new file mode 100644 index 0000000..a5ed651 --- /dev/null +++ b/.claude/tasks/plans/2026-11-10-banner-effective-profile-1015.md @@ -0,0 +1,83 @@ +# 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.sh` `detect_uiux_pro_max` only tests the plugin cache: installed = on. A project whose effective profile disables it (dev, minimal, seo, qa, audit) still shows `ui-ux-pro-max` in the 🟢 ON row. +- `hooks/session-start.sh` ✅ ON row (≈:200-219) greps `"@": true` in `$HOME/.claude/settings.json` (user scope). A project profile that enables `pr-review-toolkit` (max, audit) is not shown; one that disables a user-enabled plugin still shows it. +- `PROFILE_PLAIN` (session-start ≈:98-100, one `profile.sh -C "$PWD" current --plain` run, exported) already holds the effective state: `pack-*=on|off` lines and `plugin:=on|off` lines 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_gstack` already reads it. +- G4: `agents/status-reporter.md:23` "Active plugins (from session-start detection)" and :35 "Check `~/.claude/plugins/cache` for active marketplace plugins" (cache = installed, not active); :181 error row ties ON to the cache. `agents/plugin-probe.md:22` labels `claude plugin list` "(ids, enabled state)" and the PROBE REPORT `PLUGINS` field (: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 --plain` prints `plugin: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 calls `detect_uiux_pro_max` for 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:=on` in the effective profile for the ids lib/profiles manages (BDR-134); for an id the profile does not list, `"": 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 +1. `lib/detect-plugins.sh`: + - header lines 6-7: `detect_*` return 0/1 silently; `detect_plan` and `list_on_plugins` print to stdout. + - new function `list_on_plugins` above `# --- Toggle plugins ---` (or in a short "Effective plugin state" block), pipefail-safe, always `return 0`, no pipeline whose status matters, set difference in awk (no `grep -f` on a possibly empty file): + ```bash + 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/.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 + } + ``` + (printf always emits at least one line, so FNR == NR stays a valid first-file test even when `plain` is 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). +2. `hooks/session-start.sh` ✅ ON row: the while-loop reads `done < <(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-router` shown; real order on a default project: `rtk model-router security-guidance` (profile lines sort by id). Empty lines skipped. +3. `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"` and `bash "$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 by `list_on_plugins` (part before `@`) + the `pack-*=on` packs. + - Error table :181 → cache unreadable: no effect on `Plugins ON:`; `profile-unavailable` → `Plugins ON:` from `list_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). +4. `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). +5. `agents/plugin-advisor.md` INPUT section (after :22-27), one sentence: "`ACTIVE:` = the managed ids from `PROFILE` (`pack-*=on`, `plugin:=on`); an id absent from PROFILE keeps its `PLUGINS` enabled state (user scope); CLIs from `CLIS`. `PLUGINS` alone is installed state, never per-project." No output-format change (D3 untouched). +6. Regression test: new `lib/tests/session-banner.test.sh` (Makefile SUITES glob picks it up), `set -u` like its neighbours, summary line `session-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); no `rm` in the body: + - `WORK=$(mktemp -d)`, cleanup only by the `trap 'rm -rf "$WORK"' EXIT` of 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/lib` and `.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/lib` symlink (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-plugins` true). + - Guard before writing any fixture file: `[ ! -L "$h/.claude/settings.json" ] && [ ! -L "$h/.claude/plugins" ]`, else exit 1. + - rtk pinned: executable `rtk` stub (`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 `✅ ON` line plus the next line when it is a continuation (`│` + 13 spaces); `toggleon` = `🟢 ON` line plus continuation; `toggleoff` = `⚫ OFF` line plus continuation. Every assertion, positive and negative, runs over these. + Cases: + - SB1 dev (h1): toggleon lacks `ui-ux-pro-max`, toggleoff has it; onrow has `rtk`, `model-router`, `security-guidance`, `foo-extra`; lacks `pr-review-toolkit`, `pack-seo`. + - SB2 audit (h1): onrow has `pr-review-toolkit`; toggleon lacks `ui-ux-pro-max`. + - SB3 full (h1): toggleon has `ui-ux-pro-max`; onrow lacks `pr-review-toolkit`. + - SB4 `detect_uiux_pro_max` sourced 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_plugins` prints `security-guidance@claude-code-plugins`, `ui-ux-pro-max@ui-ux-pro-max-skill`, `foo-extra@somewhere`, not `pack-seo@skills-dir`. + - SB6 pipefail (h4, pfull), in a subshell with `set -euo pipefail` (doctor.sh options): `detect_uiux_pro_max` → 0 and `list_on_plugins` rc 0 and the subshell survives. + Red before the fix: SB1 (ui-ux in 🟢), SB2 (pr-review hidden), SB4 dev/h1, SB5/SB6 (function absent). +7. 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-dir` true at user scope: excluded. +- doctor.sh (`set -euo pipefail`): `detect_uiux_pro_max` and `list_on_plugins` never 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).