diff --git a/.gitignore b/.gitignore index aaf3d4e..7e565ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,80 +1,10 @@ # ── claude-config repo ignores ── -# GStack skill symlinks — auto-created by gstack setup -# Only the gstack/ dir itself + all symlinked skills inside skills/ +# Core skills linked flat by link.sh (symlinks, machine-owned); the heavy groups live in skills/pack-*/ as tracked symlinks. skills/gstack -skills/autoplan -skills/benchmark -skills/browse -skills/canary -skills/careful -skills/codex -skills/connect-chrome -skills/cso -skills/design-consultation -skills/design-html -skills/design-review -skills/design-shotgun -skills/devex-review -skills/diagram -skills/document-release -skills/freeze -skills/gstack-upgrade -skills/guard -skills/health -skills/investigate -skills/land-and-deploy -skills/learn -skills/office-hours -skills/open-gstack-browser -skills/pair-agent -skills/plan-ceo-review -skills/plan-design-review -skills/plan-devex-review -skills/plan-eng-review -skills/qa -skills/qa-only -skills/retro -skills/review -skills/setup-browser-cookies -skills/setup-deploy -skills/ship -skills/unfreeze -skills/benchmark-models -skills/context-restore -skills/context-save -skills/make-pdf -skills/plan-tune -skills/spec -skills/document-generate -skills/landing-report -skills/scrape -skills/setup-gbrain -skills/skillify -skills/sync-gbrain -# iOS device-farm skills (need a Mac daemon + Tailscale + iOS devices) — -# not linked on this Linux host; ignored so they stay out of git if a -# future gstack setup on a Mac host materializes the symlinks. -skills/ios-clean -skills/ios-design-review -skills/ios-fix -skills/ios-qa -skills/ios-sync - -# External skill symlinks — auto-created by link.sh -skills/design-motion-principles -skills/emil-design-eng -skills/frontend-design skills/ci-cd-and-automation skills/deprecation-and-migration skills/observability-and-instrumentation -skills/scroll-world-storytelling -skills/build-threejs-scroll-worlds -skills/scroll-scrubbed-visual-sequence -skills/scroll-scrubbed-word-reveal -skills/scroll-progress-timeline - -# superpowers, vendored (plugins.lock.json 'superpowers') skills/brainstorming skills/writing-plans skills/subagent-driven-development @@ -83,10 +13,11 @@ skills/requesting-code-review skills/using-git-worktrees skills/writing-skills -# Impeccable — NOT a symlink: `impeccable skills install --scope=global` -# writes the skill dir (and its ~15 MB engine binary) straight in through the -# ~/.claude/skills symlink. Machine-owned, regenerated by make plugin/update. +# Impeccable — `impeccable skills install --scope=global` writes +# skills/impeccable/ through the ~/.claude/skills symlink; install-plugins.sh +# moves it to skills-external/impeccable (pack-design links it). Machine-owned. skills/impeccable +skills-external/impeccable/ # …and the 4 subagents the same installer drops through ~/.claude/agents. # agents/ is a tracked directory, so these need naming explicitly. @@ -95,17 +26,6 @@ agents/impeccable-*.md # External skills installed via `npx skills add` — auto-created by link.sh skills/darwin-skill -# 21st.dev skill pack symlinks — created on demand by toggle-external.sh / -# profile.sh (the pack is DISABLED by default, so these usually don't exist). -# A glob, not one line per skill: the `21st skills install` manifest owns the -# membership, so the pack can gain a skill with no edit here. -skills/21st-* - -# Higgsfield skill pack symlinks — created on demand by toggle-external.sh -# (`enable higgsfield` / `enable higgsfield-websites`). The pack is OFF by -# default and in no profile, so these usually don't exist. -skills/higgsfield-* - # Context7 docs-lookup skill — installed by `ctx7 setup --claude --cli` # (install-plugins.sh Step 6, when absent) into ~/.claude/skills (a symlink to # this repo's skills/). ctx7-managed and re-created on demand — not vendored here. @@ -115,9 +35,6 @@ skills/find-docs/ # symlink to this repo's rules/). ctx7-managed — not vendored here. rules/context7.md -# Staging area used by lib/toggle-external.sh when disabling a tool -skills-disabled/ - # Local project config (per-machine, not shared) .claude/* !.claude/tasks/ @@ -184,8 +101,6 @@ desktop.ini .idea/ .vscode/ -# Profile cache — written by lib/profile.sh, read by hooks/statusline.sh -.active-profile .gstack/ # Frontend Design (Anthropic) — installed/refreshed from the example-skills diff --git a/agents/client-handover-writer.md b/agents/client-handover-writer.md index 7d7df18..b4d84ce 100644 --- a/agents/client-handover-writer.md +++ b/agents/client-handover-writer.md @@ -269,14 +269,14 @@ For web projects, dispatch in **a single message with two parallel Agent calls** | Audit (web) | Subagent | Prompt template | |---------------|-------------------|-----------------| -| SEO + GEO | `general-purpose` | "Read `~/.claude/skills/seo/SKILL.md` and execute it on this project. The /seo skill runs SEO + GEO in parallel and writes a unified report to `.claude/audits/SEO.md`. Run it in conservative mode: apply NOTHING, return the FIX BUNDLE (the handover main loop applies it — see 'Applying the bundle'). At the top of the report, the /seo skill MUST emit two distinct labeled score lines (already specified in its SKILL.md §1): `Score SEO (classique) : X.X / 20` and `Score GEO (IA) : X.X / 20`, plus the weighted global. The handover orchestrator parses SEO and GEO separately, so do not collapse them into a single `Score:` line. Return when the report file is written." | +| SEO + GEO | `general-purpose` | "Read `~/.claude/skills/pack-seo/skills/seo/SKILL.md` and execute it on this project. The /seo skill runs SEO + GEO in parallel and writes a unified report to `.claude/audits/SEO.md`. Run it in conservative mode: apply NOTHING, return the FIX BUNDLE (the handover main loop applies it — see 'Applying the bundle'). At the top of the report, the /seo skill MUST emit two distinct labeled score lines (already specified in its SKILL.md §1): `Score SEO (classique) : X.X / 20` and `Score GEO (IA) : X.X / 20`, plus the weighted global. The handover orchestrator parses SEO and GEO separately, so do not collapse them into a single `Score:` line. Return when the report file is written." | | HARDEN | `general-purpose` | "Read `~/.claude/skills/harden/SKILL.md` and execute it on this project with `--fix` up to READY TO APPLY only: prepare the FIX BUNDLE (security headers, HSTS, CSP, HTTP→HTTPS redirects, canonical, 404 page), apply NOTHING — the handover main loop gates and applies it (see 'Applying the bundle'). Write report to `.claude/audits/HARDEN.md` with `Score: X/20` (or `X/100`) at the top. Return when the report file is written." | Non-web variant: | Audit (non-web) | Subagent | Prompt template | |-----------------|-------------------|-----------------| -| CSO | `general-purpose` | "Read `~/.claude/skills/cso/SKILL.md` and execute in **daily mode** (8/10 confidence gate). Apply NOTHING: return the fixes as a FIX BUNDLE (gitignore additions and placeholder swaps tagged AUTO, dependency upgrades tagged GATED — the handover main loop applies AUTO and gates the rest, see 'Applying the bundle'). Write report to `.claude/audits/CSO.md` with `Score: X/20` (or `X/100`) at the top." | +| CSO | `general-purpose` | "Read `~/.claude/skills/pack-gstack-dev/skills/cso/SKILL.md` and execute in **daily mode** (8/10 confidence gate). Apply NOTHING: return the fixes as a FIX BUNDLE (gitignore additions and placeholder swaps tagged AUTO, dependency upgrades tagged GATED — the handover main loop applies AUTO and gates the rest, see 'Applying the bundle'). Write report to `.claude/audits/CSO.md` with `Score: X/20` (or `X/100`) at the top." | Wait for both subagents to complete (parallel return). @@ -426,7 +426,7 @@ for CSO) in the format Send to `general-purpose` subagent (`model: "fable"`, `effort="high"`): -> Read `~/.claude/skills/seo/SKILL.md` and re-run it on this project in +> Read `~/.claude/skills/pack-seo/skills/seo/SKILL.md` and re-run it on this project in > **conservative (audit-only) intervention mode**: re-score and leave both > FIX BUNDLEs in `.claude/audits/SEO.md` ready-to-apply. Apply NOTHING and > ask the user NOTHING — the handover main loop is the dispatcher: it @@ -470,7 +470,7 @@ Send to `general-purpose` subagent (`model: "fable"`, `effort="high"`): Send to `general-purpose` subagent (`model: "fable"`, `effort="high"`): -> Read `~/.claude/skills/cso/SKILL.md` and re-run it in **daily mode**. +> Read `~/.claude/skills/pack-gstack-dev/skills/cso/SKILL.md` and re-run it in **daily mode**. > Previous score: **``/20** — below threshold. > Iteration `` of ``. Apply NOTHING: return the fixes as > a FIX BUNDLE in `.claude/audits/CSO.md` — gitignore additions and secret @@ -679,7 +679,7 @@ VALIDATE as not-applicable rather than failed). Dispatch `general-purpose` subagent (`model: "fable"`, `effort="high"`): -> Read `~/.claude/skills/web-validate/SKILL.md` and execute against the +> Read `~/.claude/skills/pack-web-validate/skills/web-validate/SKILL.md` and execute against the > deployed URL: ``. Audit W3C HTML validity (validator.nu), > W3C CSS validity (jigsaw.w3.org), WCAG 2.1 a11y (axe-core, pa11y). > Apply NOTHING (the client controls deploy; the handover main loop applies diff --git a/agents/plugin-advisor.md b/agents/plugin-advisor.md index 4e1aa2e..f08281c 100644 --- a/agents/plugin-advisor.md +++ b/agents/plugin-advisor.md @@ -219,7 +219,7 @@ RULE: IF "monorepo" signal detected: RULE: IF "frontend" signal OR .tsx/.jsx count > 0: → ui-ux-pro-max ON if "design-system" signal (~400t) - → impeccable ON (external skill, 0t passive — ~/.claude/skills/impeccable) + → impeccable ON (external skill, 0t passive — ~/.claude/skills/pack-design/skills/impeccable) → design-motion-principles ON if anim-lib-installed or description mentions animation/motion (external, 0t passive) RULE: IF "deploy" AND "browser-qa" signals: diff --git a/install-plugins.sh b/install-plugins.sh index 9a6b85d..c09275b 100644 --- a/install-plugins.sh +++ b/install-plugins.sh @@ -749,10 +749,10 @@ else fi fi # Symlink handled by link.sh -if [ -L "$HOME/.claude/skills/emil-design-eng" ]; then - ok "emil-design-eng symlink OK" +if [ -L "$HOME/.claude/skills/pack-design/skills/emil-design-eng" ]; then + ok "emil-design-eng linked by pack-design" else - info "Symlinking — will be created by link.sh" + info "pack-design link not present yet (git checkout)" fi echo "" @@ -774,10 +774,10 @@ else warn "frontend-design: anthropic-agent-skills plugin not cached — install via: claude plugin install example-skills@anthropic-agent-skills" fi fi -if [ -L "$HOME/.claude/skills/frontend-design" ]; then - ok "frontend-design symlink OK" +if [ -L "$HOME/.claude/skills/pack-design/skills/frontend-design" ]; then + ok "frontend-design linked by pack-design" else - info "Symlinking — will be created by link.sh" + info "pack-design link not present yet (git checkout)" fi echo "" @@ -790,10 +790,10 @@ if [ -f "$DMP_DIR/SKILL.md" ]; then else warn "design-motion-principles: not installed — clone from https://github.com/kylezantos/design-motion-principles" fi -if [ -L "$HOME/.claude/skills/design-motion-principles" ]; then - ok "design-motion-principles symlink OK" +if [ -L "$HOME/.claude/skills/pack-design/skills/design-motion-principles" ]; then + ok "design-motion-principles linked by pack-design" else - info "Symlinking — will be created by link.sh" + info "pack-design link not present yet (git checkout)" fi echo "" @@ -1323,8 +1323,8 @@ echo " 🔄 higgsfield pack — Higgsfield CLI media skills (image, video echo "" echo " All plugins installed at: user scope (~/.claude/plugins/)" echo " GStack skills symlinked individually into ~/.claude/skills/ (→ submodule)" -echo " Emil Design Eng at: ~/.claude/skills/emil-design-eng/ (symlink → skills-external)" -echo " Frontend Design at: ~/.claude/skills/frontend-design/ (symlink → skills-external)" +echo " Emil Design Eng at: ~/.claude/skills/pack-design/skills/emil-design-eng/ (symlink → skills-external)" +echo " Frontend Design at: ~/.claude/skills/pack-design/skills/frontend-design/ (symlink → skills-external)" echo " Design Motion Principles at: ~/.claude/skills/design-motion-principles/ (symlink → skills-external)" echo " Agent Skills trio at: ~/.claude/skills/{observability-and-instrumentation,deprecation-and-migration,ci-cd-and-automation}/ (symlink → skills-external)" echo " Mengto scroll skills at: ~/.claude/skills/{scroll-world-storytelling,build-threejs-scroll-worlds,scroll-scrubbed-visual-sequence,scroll-scrubbed-word-reveal,scroll-progress-timeline}/ (symlink → skills-external)" diff --git a/lib/detect-plugins.sh b/lib/detect-plugins.sh index f641e57..c4f82cd 100644 --- a/lib/detect-plugins.sh +++ b/lib/detect-plugins.sh @@ -26,10 +26,11 @@ detect_superpowers() { # --- Toggle plugins --- detect_gstack() { - # gstack is exposed via per-skill symlinks (browse, canary, qa, …); + # gstack is exposed via per-skill symlinks in pack-gstack-* (browse, canary, qa, …); # the legacy top-level symlink was removed to avoid duplicate entries. # Detect by checking any of its individual skills. - [ -L "$HOME/.claude/skills/browse" ] || [ -L "$HOME/.claude/skills/qa" ] + [ -L "$HOME/.claude/skills/pack-gstack-browser/skills/browse" ] \ + || [ -L "$HOME/.claude/skills/pack-gstack-browser/skills/qa" ] } detect_gsd() { diff --git a/lib/gstack-removed.list b/lib/gstack-removed.list new file mode 100644 index 0000000..0d8fc6f --- /dev/null +++ b/lib/gstack-removed.list @@ -0,0 +1,9 @@ +ship +land-and-deploy +setup-deploy +autoplan +context-save +learn +careful +guard +design-shotgun diff --git a/lib/gstack-removed.sh b/lib/gstack-removed.sh index 76e2976..33c8e18 100644 --- a/lib/gstack-removed.sh +++ b/lib/gstack-removed.sh @@ -2,11 +2,11 @@ # ============================================================ # lib/gstack-removed.sh — the gstack skills this config never exposes # -# Single source for the denylist. Sourced by lib/profile.sh -# (enable_all_gstack, enable_skill) and lib/toggle-external.sh -# (`enable gstack`), read by lib/tests/profile-census.test.sh. A name -# listed here is in no profile, `max` included, and every "bring gstack -# back" path skips it. Decided 2026-09-28 (skill-catalog prune, user go): +# The denylist itself lives in gstack-removed.list (one name per line), +# read here into GSTACK_REMOVED and by lib/pack-census.sh. A name listed is +# in no pack and no profile, `max` included. Pruned 2026-09-28 (BDR-105), +# helpers housed here per BDR-117, retired with the symlink toggling. +# Why each name went: # # ship base = origin/HEAD = main on Gitea, skips develop # land-and-deploy `gh pr merge --squash --delete-branch` then deploys @@ -19,67 +19,7 @@ # house permissions.deny is stricter (BDR-095) # design-shotgun mockups need OPENAI_API_KEY, absent # -# Also hosts the gstack helpers the two scripts share (gstack_skills and -# the park/unpark moves below). They live in this file because it is the -# only one the fixture suites copy next to profile.sh / toggle-external.sh: -# a new sourced file would be missing there. Each takes its directories as -# arguments (no reliance on the caller's globals). -# -# No `set -euo pipefail` here (sourced lib, mirrors lib/detect-plugins.sh). +# No `set -euo pipefail` here (sourced lib). # ============================================================ -GSTACK_REMOVED=(ship land-and-deploy setup-deploy autoplan context-save - learn careful guard design-shotgun) - -# gstack_is_removed — exit 0 when is on the denylist. -gstack_is_removed() { - local name="$1" entry - for entry in "${GSTACK_REMOVED[@]}"; do - [ "$entry" = "$name" ] && return 0 - done - return 1 -} - -# gstack_skills — prints the directory basenames under -# /*/ that hold a SKILL.md; nothing when the dir is absent. -# Source of truth for "which skills belong to gstack". -gstack_skills() { - local src="$1" d - [ -d "$src" ] || return 0 - for d in "$src"/*/; do - [ -f "${d}SKILL.md" ] || continue - basename "$d" - done -} - -# gstack_parked_names — prints for every -# /gstack__ entry (a dangling symlink is skipped). -gstack_parked_names() { - local entry - [ -d "$1" ] || return 0 - for entry in "$1"/gstack__*; do - [ -e "$entry" ] || continue - basename "$entry" | sed 's/^gstack__//' - done -} - -# gstack_park — moves skills/ to -# skills-disabled/gstack__. A stale destination is clobbered first: -# gstack ./setup creates skills// as directories, so mv onto an -# existing dir would nest it (gstack__//) instead of renaming. -# Content is symlinks to the submodule, `gstack ./setup` regenerates it. -# Call as a plain statement (never `|| …`, `if`, `!`): errexit must stay on. -gstack_park() { - local skills_dir="$1" disabled_dir="$2" name="$3" - rm -rf "$disabled_dir/gstack__$name" - mv "$skills_dir/$name" "$disabled_dir/gstack__$name" -} - -# gstack_unpark — moves -# skills-disabled/gstack__ back to skills/, replacing whatever -# sits there. Same plain-statement rule as gstack_park. -gstack_unpark() { - local skills_dir="$1" disabled_dir="$2" name="$3" - rm -rf "${skills_dir:?}/${name:?}" - mv "$disabled_dir/gstack__$name" "$skills_dir/$name" -} +mapfile -t GSTACK_REMOVED < "$(dirname "${BASH_SOURCE[0]}")/gstack-removed.list" diff --git a/lib/higgsfield-skills.sh b/lib/higgsfield-skills.sh index 6721a2e..332274f 100644 --- a/lib/higgsfield-skills.sh +++ b/lib/higgsfield-skills.sh @@ -4,9 +4,8 @@ # # Sourced by install-plugins.sh (Step 8.6), update-all.sh (7.3b) and # doctor.sh. The pack is machine-owned: cloned from upstream and moved -# into skills-external/higgsfield-* (gitignored), then linked on demand by -# lib/toggle-external.sh. It is listed in neither link.sh nor any profile: -# either would re-enable a parked pack on every run (BDR-093). +# into skills-external/higgsfield-* (gitignored), then linked by +# skills/pack-higgsfield (`profile.sh enable higgsfield`). # ============================================================ # Upstream skills repo, single source for both installers. An env value @@ -38,8 +37,8 @@ _higgsfield_adopt() { # The stage sits next to the destination, on the same filesystem, so each # replacement is a rename. Prints the number of skills synced. Returns 1, # existing copies untouched, when the clone fails or upstream holds no -# higgsfield-*/SKILL.md. A parked skill (skills-disabled/, a symlink -# to the source path) stays parked. Known limit: a skill that upstream +# higgsfield-*/SKILL.md. Linked by skills/pack-higgsfield (`profile.sh +# enable higgsfield`), never touched here. Known limit: a skill that upstream # removes or renames keeps its last local copy. higgsfield_sync_skills() { local dest="$1/skills-external" stage count=0 diff --git a/lib/pack-census-fragments.jq b/lib/pack-census-fragments.jq new file mode 100644 index 0000000..dcec72f --- /dev/null +++ b/lib/pack-census-fragments.jq @@ -0,0 +1,32 @@ +# lib/pack-census-fragments.jq — fragment invariants (lib/pack-census.sh). +# $m = manifests [{id,on}], $deny = space-separated profiles that deny the +# two higgsfield connectors; inputs = lib/profiles/*.json. Prints RED lines. +def name_of: input_filename | sub(".*/"; ""); +def dn: [(.deniedMcpServers // [])[] | .serverName] | sort; +[inputs | {f: name_of, frag: .}] as $all +| ($all[] | select(.f == "full.json") | .frag) as $full +| ($full.enabledPlugins | keys) as $keys +| ($deny | split(" ") | map(. + ".json")) as $deny_files +| ($m | map({key: .id, value: .on}) | from_entries) as $mdef +| $all[] +| .f as $f | .frag as $g +| ( if ($g.enabledPlugins | keys) != $keys + then "RED lib/profiles/\($f): key set differs from full.json" + else empty end ), + ( ["model-router@skills-dir", "security-guidance@claude-code-plugins"][] + | select($g.enabledPlugins[.] != true) + | "RED lib/profiles/\($f): \(.) must be true" ), + ( ["example-skills@anthropic-agent-skills", "brightdata-plugin@synced"][] + | select($g.enabledPlugins[.] != false) + | "RED lib/profiles/\($f): \(.) must be false" ), + ( (["claude.ai higgsfield", "claude.ai Higgsfield AI"] | sort) as $both + | if (($deny_files | index($f)) != null) and (($g | dn) != $both) + then "RED lib/profiles/\($f): must deny both higgsfield connectors" + elif (($deny_files | index($f)) == null) and (($g | dn) | length) > 0 + then "RED lib/profiles/\($f): must deny no connector" + else empty end ), + ( if $f == "full.json" then + ($mdef | to_entries[] | select($g.enabledPlugins[.key] != .value) + | "RED lib/profiles/full.json: \(.key) is \($g.enabledPlugins[.key])" + + " but the manifest default is \(.value)") + else empty end ) diff --git a/lib/pack-census.sh b/lib/pack-census.sh new file mode 100755 index 0000000..bd9a68e --- /dev/null +++ b/lib/pack-census.sh @@ -0,0 +1,130 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2088 # the literal "~/.claude/skills" is a grep pattern +# ============================================================ +# lib/pack-census.sh — census of the pack layout and its readers +# +# Packs are skills-dir plugins `skills/pack-/` (manifest +# `.claude-plugin/plugin.json`, entries `skills/` = tracked relative +# symlinks into skills-external/ or real dirs). Checks: +# 1. manifest parses, name = folder; every entry resolves (dangling = +# WARN; RED with --installed on a pack ON by manifest); no skill both +# flat and in a pack; no retired gstack name (lib/gstack-removed.list). +# 2. fragments lib/profiles/*.json: same key set as full.json; model-router +# + security-guidance true, example-skills + brightdata false +# everywhere; the two higgsfield connectors denied on exactly +# DENY_PROFILES; full.json packs = manifest defaults. +# 3. no reader of the old layout left (scope and terms in check_citers). +# Shared by make test (lib/tests/pack-census.test.sh) and doctor.sh. +# Prints RED/WARN lines, then `PACKS OK

packs skills` when no RED. +# Exit: 0 clean or WARN only · 1 any RED. +# Usage: pack-census.sh [--repo

] [--installed] +# ============================================================ +set -euo pipefail + +REPO="$(cd -P "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +INSTALLED=0 +while [ $# -gt 0 ]; do + case "$1" in + --repo) REPO="$2"; shift 2 ;; + --installed) INSTALLED=1; shift ;; + *) echo "pack-census: unknown option $1" >&2; exit 2 ;; + esac +done +SKILLS="$REPO/skills" +PROFILES="$REPO/lib/profiles" +REMOVED="$REPO/lib/gstack-removed.list" +HERE="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +FRAG_JQ="$HERE/pack-census-fragments.jq" +DENY_PROFILES="audit backend dev minimal qa seo" # spec § 2 +red=0; packs=0; skills=0 +declare -A seen +red() { echo "RED $*"; red=1; } + +pack_on() { + jq -e '.defaultEnabled != false' "$1/.claude-plugin/plugin.json" >/dev/null +} + +check_manifest() { # $1 pack dir + local n m name; n="$(basename "$1")"; m="$1/.claude-plugin/plugin.json" + [ -f "$m" ] || { red "$n: no .claude-plugin/plugin.json"; return; } + jq -e . "$m" >/dev/null 2>&1 || { red "$n: manifest is not JSON"; return; } + name="$(jq -r '.name // ""' "$m")" + [ "$name" = "$n" ] || red "$n: manifest name is $name" +} + +check_entry() { # $1 pack dir, $2 entry path + local n s; n="$(basename "$1")"; s="$(basename "$2")" + if [ ! -e "$2/SKILL.md" ]; then + if [ "$INSTALLED" = 1 ] && pack_on "$1"; then + red "$n: $s target missing (pack ON)" + else echo "WARN $n: $s target missing (installer not run)"; fi + fi + [ -f "$REMOVED" ] && grep -qx -- "$s" "$REMOVED" \ + && red "$n: $s is a retired gstack skill" + if [ -n "${seen[$s]:-}" ]; then + red "$s listed twice: ${seen[$s]} and $n — rm ${seen[$s]} (a flat link)" + else seen[$s]="$n"; fi + skills=$((skills+1)) +} + +check_fragments() { + local files=("$PROFILES"/*.json) full="$PROFILES/full.json" out + [ -f "$full" ] || { red "lib/profiles/full.json missing"; return; } + out="$(jq -rn --arg deny "$DENY_PROFILES" --argjson m "$(manifests_json)" \ + -f "$FRAG_JQ" "${files[@]}")" \ + || { red "lib/profiles: a fragment is not JSON"; return; } + [ -z "$out" ] || { echo "$out"; red=1; } +} + +manifests_json() { # [{id, on}] for every pack manifest + jq -cn '[inputs | {id: (.name + "@skills-dir"), + on: (.defaultEnabled != false)}]' \ + "$SKILLS"/pack-*/.claude-plugin/plugin.json 2>/dev/null || echo '[]' +} + +# The old-layout terms are written with a bracketed last letter so this +# file never matches itself; the test's fixture strings live in +# lib/tests/fixtures/ (excluded) for the same reason. +check_citers() { # $@ pack skill names → one grep over the contract scope + local args=(-e 'skills-disable[d]/' -e 'toggle-externa[l]' + -e '\.active-profil[e]' -e 'lib/profiles/[a-z-]*\.profil[e]') n hit + for n in "$@"; do + args+=(-e "~/.claude/skills/$n\b" -e "\$HOME/.claude/skills/$n\b") + done + hit="$( { grep -rno --include='*.sh' --include='*.md' --include='*.py' \ + --include='*.json' --include='Makefile' "${args[@]}" "$REPO"/hooks \ + "$REPO"/lib "$REPO"/agents "$REPO"/skills "$REPO"/rules \ + "$REPO"/templates "$REPO"/mods "$REPO"/*.sh "$REPO"/CLAUDE.global.md \ + "$REPO"/README.md "$REPO"/USAGE.md "$REPO"/ARCHITECTURE.md \ + "$REPO"/Makefile "$REPO"/plugins.lock.json 2>/dev/null + grep -nHo "${args[@]}" "$REPO"/.gitignore 2>/dev/null; } \ + | grep -v -e '/lib/tests/fixtures/' -e '/skills/pack-' \ + -e '/skills-external/' \ + | sed 's#:[0-9]*:#\t#' | sort -u || true)" + [ -n "$hit" ] || return 0 + while IFS=$'\t' read -r f m; do + red "${f#"$REPO"/} cites $m" + done <<<"$hit" +} + +main() { + local d s p e names=() + [ -f "$REMOVED" ] || red "lib/gstack-removed.list missing" + for d in "$SKILLS"/*/; do + d="${d%/}"; s="$(basename "$d")" + case "$s" in pack-*) continue ;; esac + [ -e "$d/SKILL.md" ] && seen[$s]="skills/$s" + done + for p in "$SKILLS"/pack-*/; do + p="${p%/}"; packs=$((packs+1)); check_manifest "$p" + for e in "$p"/skills/*; do + [ -e "$e" ] || [ -L "$e" ] || continue + check_entry "$p" "$e"; names+=("$(basename "$e")") + done + done + check_fragments + [ "${#names[@]}" -gt 0 ] && check_citers "${names[@]}" + [ "$red" -eq 0 ] && echo "PACKS OK $packs packs $skills skills" + exit "$red" +} +main diff --git a/lib/profile-state.jq b/lib/profile-state.jq new file mode 100644 index 0000000..3a670ae --- /dev/null +++ b/lib/profile-state.jq @@ -0,0 +1,70 @@ +# lib/profile-state.jq — effective profile state of one project and +# conversation, in one pass (lib/profile.sh `current`, `unset`). +# Args: $u $p $l $f raw settings files (user, project, local, --settings; +# "" when absent), $cj raw ~/.claude.json, $m manifests [{id,on}], +# $mode "plain" | "human" | "json", $proj project dir, $flagname CLAUDE_PROFILE +# or "-", $hasflag "1" when a --settings file is in force. +# inputs = lib/profiles/*.json (one fragment per file). +def parse: try fromjson catch {}; +def name_of: input_filename | sub(".*/"; "") | sub("\\.json$"; ""); +def ep: (.enabledPlugins // {}); +def dn: [(.deniedMcpServers // [])[] | .serverName]; +def onoff: if . then "on" else "off" end; +def is_pack: startswith("pack-") and endswith("@skills-dir"); +def short: sub("@skills-dir$"; ""); +def src_word($s): + if $s.source == "flag" then "conv \($s.flag)" else $s.source end; +def listing($plugins; $on): + [$plugins | to_entries[] | select(.value == $on) | .key | short] + | if length == 0 then "none" else join(" ") end; + +[inputs | {name: name_of, frag: .}] as $profiles +| ($u | parse) as $U | ($p | parse) as $P +| ($l | parse) as $L | ($f | parse) as $F +| ([$profiles[].frag | ep | keys[]] | unique) as $ids +| ($m | map({key: .id, value: .on}) | from_entries) as $mdef +| ($ids | map({key: ., value: ($mdef[.] + // (if endswith("@skills-dir") and (is_pack | not) then true + else false end))}) | from_entries) as $d +| (($d + ($U|ep) + ($P|ep) + ($L|ep) + ($F|ep)) + | with_entries(select(.key as $k | $d | has($k)))) as $plugins +| ((($U|dn) + ($P|dn) + ($L|dn) + ($F|dn)) | unique) as $denied +| ([$U, $P, $L, $F] | any(.disableClaudeAiConnectors == true)) as $all +| ($F.model // $L.model // $P.model // $U.model // "-") as $model +| (if ($F | has("model")) then "flag" elif ($L | has("model")) then "local" + elif ($P | has("model")) then "project" + elif ($U | has("model")) then "user" else "-" end) as $msrc +| (if $hasflag == "1" then "flag" + elif ((($L|ep) | length) + (($L|dn) | length)) > 0 then "local" + else "default" end) as $src +| (try ($cj | fromjson | .projects[$proj].disabledMcpServers // [] + | if length == 0 then "-" else join(",") end) + catch (if $cj == "" then "-" else "unknown" end)) as $off +| ([$profiles[] | select((.frag | ep) == $plugins + and ((.frag | dn | sort) == ($denied | sort)) and ($all | not)) + | .name] | .[0] // "custom") as $name +| {name: $name, source: $src, flag: $flagname, plugins: $plugins, + denied: $denied, all_denied: $all, model: $model, model_source: $msrc, + mcp_off: $off} as $s +| if $mode == "json" then $s + elif $mode == "plain" then + ( ["profile=\($s.name)", "source=\($s.source)", "flag=\($s.flag)"] + + [$plugins | to_entries | sort_by(.key)[] | select(.key | is_pack) + | "\(.key | short)=\(.value | onoff)"] + + [$plugins | to_entries | sort_by(.key)[] + | select(.key | is_pack | not) | "plugin:\(.key)=\(.value | onoff)"] + + [$denied[] | "connector:\(.)=denied"] + + (if $all then ["connector:*=denied"] else [] end) + + ["model=\($s.model)", "model-source=\($s.model_source)", + "mcp-off=\($s.mcp_off)"] ) | .[] + else + ( [ (if $s.mcp_off != "-" + then "profile: custom (off: \($s.mcp_off)) [\(src_word($s))]" + else "profile: \($s.name) [\(src_word($s))]" end), + " on : \(listing($plugins; true))", + " off: \(listing($plugins; false))", + " connectors denied: \(if $all then "all" + elif ($denied | length) == 0 then "none" + else ($denied | join(", ")) end)", + " model: \($s.model) (\($s.model_source))" ] ) | .[] + end diff --git a/lib/profile.sh b/lib/profile.sh index 20c9800..089d981 100755 --- a/lib/profile.sh +++ b/lib/profile.sh @@ -1,834 +1,269 @@ #!/usr/bin/env bash +# shellcheck disable=SC2016 # jq programs quote $vars on purpose # ============================================================ -# lib/profile.sh — Partition Claude skills + plugins + MCPs by purpose +# lib/profile.sh — profiles as settings fragments for packs + connectors # -# Profiles group skills (gstack + external + personal), plugins, MCPs, -# and CLIs for a specific kind of work: web, seo, web-full, backend, -# design, dev, qa, audit, minimal. Apply a profile to enable just the -# relevant tools and disable the rest, instead of carrying every gstack -# skill + every plugin in every session. -# -# Mechanism: -# - Skills (gstack/external/personal): symlink toggle skills/ ↔ skills-disabled/ -# - Plugins: `claude plugin enable|disable @` -# - MCPs: advisory (none managed since BDR-093 — MANAGED_MCPS is empty), -# advisory otherwise -# - CLIs: advisory only (rtk, gsd, ctx7, graphify — installed externally) -# - `set` is SYMMETRIC on managed items (BDR-079): plugins, external packs -# and MCPs in the MANAGED_* allowlists are disabled when the profile -# does not list them — nothing outside those lists is ever auto-toggled. -# -# Always-on plugins (never toggled by `set`): security-guidance + rtk -# hook + .claude internal. superpowers is vendored skills now, not a -# plugin (never in PROTECTED_PLUGINS, never in MANAGED_EXTERNALS — same -# always-on class as darwin-skill). The script refuses to disable -# anything in PROTECTED_PLUGINS. +# A profile `lib/profiles/.json` is a literal Claude Code settings +# fragment: `enabledPlugins` (every pack `pack-@skills-dir` and managed +# plugin, explicit true/false), `deniedMcpServers` (claude.ai connector +# names, optional) and `model` (optional). Per project, `set` merges it +# into `.claude/settings.local.json`; per conversation, `cc +# ` (lib/cc.sh) passes the file as `claude --settings`. Nothing +# here writes the user scope, moves a symlink or calls `claude`. # # Usage: -# profile.sh list list available profiles -# profile.sh show show contents of a profile (grouped by type) -# profile.sh show --plain parsable type+name list (no status, no claude) -# profile.sh current report the active profile (label + match) -# profile.sh apply enable items in profile (additive) -# profile.sh set enable only profile (disables rest) -# profile.sh reset go to the default profile (full): enable its -# list, park non-listed gstack/managed items -# profile.sh gstack on|off toggle gstack, keeping active-profile label -# profile.sh diff compare two profiles +# profile.sh [-C ] list +# profile.sh [-C ] show +# profile.sh [-C ] current [--plain] +# profile.sh [-C ] set +# profile.sh [-C ] unset +# profile.sh [-C ] enable|disable +# profile.sh [-C ] diff # -# Profile file format (lib/profiles/.profile): -# # DESC: -# # type defaults to "gstack" -# personal # personal skill (skills//SKILL.md is real) -# external # symlinked into skills-external/ -# plugin@ # Claude plugin — auto-toggle -# mcp # MCP — advisory or via toggle-external -# cli # standalone CLI — advisory only +# (default: cwd) resolves to the nearest ancestor holding .claude/, +# CLAUDE.md or .git, so a subdirectory reads its project's settings. +# `current` = lib/profile-state.jq, ONE jq pass over: $CLAUDE_PROFILE_SETTINGS +# (the --settings file lib/cc.sh exports), /.claude/settings.local.json, +# /.claude/settings.json, ~/.claude/settings.json; a pack absent from +# all takes its manifest `defaultEnabled` (absent key = on); a managed plugin +# absent from all is off; `enabledPlugins` and `model` per key, highest wins; +# `deniedMcpServers` = the UNION of every file; `disableClaudeAiConnectors` +# any-source-true; then ~/.claude.json `projects[].disabledMcpServers`. +# `--plain` = one `key=value` per line: the single truth for gates, hooks +# and the statusline (supersedes `show --plain`, BDR-024). # +# Exit: 0 ok · 2 usage, unknown profile or pack, not a project root (no +# CLAUDE.md and no .git), unreadable or invalid local JSON; nothing +# is written on any refusal. # ============================================================ set -euo pipefail -REPO="${PROFILE_REPO_OVERRIDE:-$(cd -P "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" -CLAUDE_BIN="${CLAUDE_BIN:-claude}" -SKILLS_DIR="$REPO/skills" -DISABLED_DIR="$REPO/skills-disabled" -GSTACK_SRC="$REPO/skills-external/gstack" # gstack submodule — source of truth for gstack skills +REPO="${PROFILE_REPO_OVERRIDE:-$(cd -P "$(dirname "${BASH_SOURCE[0]}")/.." \ + && pwd)}" PROFILES_DIR="$REPO/lib/profiles" -ACTIVE_CACHE="$REPO/.active-profile" # statusline reads this — keep fast (single-line file, profile name only) -DEFAULT_PROFILE="full" # profile in force when none is selected (cache absent, empty, or legacy "none") - -# GSTACK_REMOVED + gstack_is_removed() — single source, honored by every -# "bring gstack back" path below (enable_all_gstack, enable_skill) — plus the -# gstack helpers shared with toggle-external.sh (gstack_skills, gstack_park, -# gstack_unpark, gstack_parked_names). -# shellcheck source=lib/gstack-removed.sh disable=SC1091 -source "$(dirname "${BASH_SOURCE[0]}")/gstack-removed.sh" - -# Plugins that are toggle-managed by `set`. Anything NOT in this list is -# never auto-disabled — protects always-on plugins (security-guidance; -# superpowers is vendored skills now, not a plugin) and unrelated user -# plugins. Add a plugin here only when its enabled state is meaningfully -# driven by task type. -MANAGED_PLUGINS=( - "ui-ux-pro-max@ui-ux-pro-max-skill" - "plugin-dev@claude-code-plugins" - "pr-review-toolkit@claude-code-plugins" -) - -# External skill packs that are toggle-managed by `set` — same allowlist -# doctrine as MANAGED_PLUGINS: listed here only when the enabled state is -# task-type-driven. `set` disables these when the profile does not list -# them; anything else external (e.g. darwin-skill) is never auto-touched. -MANAGED_EXTERNALS=( - emil-design-eng - frontend-design - design-motion-principles - impeccable - 21st-ui-build - 21st-ui-explore - 21st-ui-review - 21st-cli-use - 21st-ai - observability-and-instrumentation - deprecation-and-migration - ci-cd-and-automation - scroll-world-storytelling - build-threejs-scroll-worlds - scroll-scrubbed-visual-sequence - scroll-scrubbed-word-reveal - scroll-progress-timeline -) - -# MCP servers that are toggle-managed by `set`, both ways (enable AND -# disable), delegated to lib/toggle-external.sh. Same allowlist doctrine. -# Empty: no MCP server is managed today (the 21st design skills are managed -# as externals above). The `mcp` type itself stays supported — a profile can -# still list an MCP, it is then advisory rather than auto-toggled. -MANAGED_MCPS=() - -# Plugins that MUST stay enabled — `set` will refuse to disable these even if -# they're not in the profile. (Defensive: belt-and-suspenders alongside -# MANAGED_PLUGINS allowlist.) -PROTECTED_PLUGINS=( - "security-guidance@claude-code-plugins" -) - -GREEN='\033[0;32m'; YELLOW='\033[1;33m'; RED='\033[0;31m'; BLUE='\033[0;34m'; NC='\033[0m' -ok() { echo -e "${GREEN}✓${NC} $1"; } -warn() { echo -e "${YELLOW}⚠${NC} $1"; } -err() { echo -e "${RED}✗${NC} $1" >&2; } -info() { echo -e "${BLUE}ℹ${NC} $1"; } - -# Persist active-profile name for fast statusline lookup (cmd_current is slow -# — iterates every profile + every entry). Write profile name only; statusline -# reads the file directly without re-invoking this script. -write_active() { - local name="$1" - printf '%s\n' "$name" > "$ACTIVE_CACHE" 2>/dev/null || true -} - -# First line of the cache, all whitespace stripped (tr -d, CRLF-proof). -# Empty string when the cache is missing or empty. Never trips -# `set -euo pipefail` (head's failure on a missing file is absorbed). -read_cache() { - head -n1 "$ACTIVE_CACHE" 2>/dev/null | tr -d '[:space:]' || true -} - -# The profile actually in force: the cached label, or DEFAULT_PROFILE when -# the cache is absent, empty, or the legacy "none" sentinel. The ONE place -# that resolves "no profile selected" — every reader of the cache goes -# through this (or read_cache() when it needs the raw value). -active_profile() { - local cached; cached="$(read_cache)" - if [ -z "$cached" ] || [ "$cached" = "none" ]; then - printf '%s' "$DEFAULT_PROFILE" - else - printf '%s' "$cached" - fi -} - -# ── Profile parsing ──────────────────────────────────────── - -# Read a profile file. Output one line per entry: "\t" -# Comments (#…) and blank lines are stripped. Default type is "gstack". -read_profile() { - local prof="$1" - local file="$PROFILES_DIR/$prof.profile" - [ -f "$file" ] || { err "Profile not found: $prof (looked in $PROFILES_DIR)"; return 1; } - local skill type rest - while IFS= read -r line || [ -n "$line" ]; do - line="${line%%#*}" - # trim leading whitespace + tabs - while [[ "$line" =~ ^[[:space:]] ]]; do line="${line#?}"; done - # trim trailing whitespace + tabs - while [[ "$line" =~ [[:space:]]$ ]]; do line="${line%?}"; done - [ -z "$line" ] && continue - # split on first whitespace run - skill="${line%%[[:space:]]*}" - rest="${line#"$skill"}" - while [[ "$rest" =~ ^[[:space:]] ]]; do rest="${rest#?}"; done - type="${rest:-gstack}" - # Validate type. Accepted forms: - # gstack | external | personal — skill (symlink toggle) - # plugin@ — Claude plugin (auto-toggle) - # plugin — legacy/advisory (no marketplace known) - # mcp — MCP server (advisory or via toggle-external) - # cli — standalone CLI (advisory only) - case "$type" in - gstack|external|personal|plugin|mcp|cli) : ;; - plugin@*) : ;; - *) warn "unknown type '$type' for entry '$skill' in $prof — defaulting to gstack"; type=gstack ;; - esac - printf '%s\t%s\n' "$skill" "$type" - done < "$file" -} - -# Profile description (line starting with "# DESC: …") -profile_desc() { - local file="$1" - grep -m1 '^# DESC:' "$file" 2>/dev/null | sed 's/^# DESC:[[:space:]]*//' || true -} - -# ── Counting & formatting helpers ───────────────────────── - -# Tally a profile's entries by category (claude-free, reads the .profile only). -# Echo: " " — skills = gstack+external+personal. -count_profile() { - local prof="$1" type - local g=0 e=0 p=0 pl=0 m=0 c=0 - while IFS=$'\t' read -r _ type; do - case "$type" in - gstack) g=$((g + 1)) ;; - external) e=$((e + 1)) ;; - personal) p=$((p + 1)) ;; - plugin@*|plugin) pl=$((pl + 1)) ;; - mcp) m=$((m + 1)) ;; - cli) c=$((c + 1)) ;; - esac - done < <(read_profile "$prof") - printf '%d %d %d %d\n' "$((g + e + p))" "$pl" "$m" "$c" -} - -# " " with a plural "s" when n != 1. -_plur() { - if [ "$1" -eq 1 ]; then printf '%d %s' "$1" "$2"; else printf '%d %ss' "$1" "$2"; fi -} - -# Format four category counts. style=compact -> "12s·1p·1m·1c"; -# style=long -> "12 skills · 1 plugin · 1 mcp · 1 cli". Zero categories are -# skipped; all-zero -> "—". -fmt_counts() { - local style="$1" skills="$2" pl="$3" m="$4" c="$5" out="" - if [ "$style" = compact ]; then - [ "$skills" -gt 0 ] && out="${skills}s" - [ "$pl" -gt 0 ] && out="${out:+$out·}${pl}p" - [ "$m" -gt 0 ] && out="${out:+$out·}${m}m" - [ "$c" -gt 0 ] && out="${out:+$out·}${c}c" - else - [ "$skills" -gt 0 ] && out="$(_plur "$skills" skill)" - [ "$pl" -gt 0 ] && out="${out:+$out · }$(_plur "$pl" plugin)" - [ "$m" -gt 0 ] && out="${out:+$out · }$(_plur "$m" mcp)" - [ "$c" -gt 0 ] && out="${out:+$out · }$(_plur "$c" cli)" - fi - printf '%s' "${out:-—}" -} - -# Right-pad a string to display width $2 (character count, UTF-8 aware). -rpad() { - local s="$1" w="$2" len=${#1} - if [ "$len" -lt "$w" ]; then printf '%s%*s' "$s" "$((w - len))" ''; else printf '%s' "$s"; fi -} - -# ── Status detection ────────────────────────────────────── - -skill_status() { - local skill="$1" type="$2" - case "$type" in - gstack|external|personal) - if [ -e "$SKILLS_DIR/$skill" ]; then - echo "enabled" - elif [ -e "$DISABLED_DIR/gstack__$skill" ] || [ -e "$DISABLED_DIR/$skill" ]; then - echo "disabled" - else - echo "missing" - fi - ;; - plugin|plugin@*) - # `claude plugin list` is the source of truth — settings.json may be - # ahead of or behind reality if the user toggled outside this tool. - if command -v "$CLAUDE_BIN" >/dev/null 2>&1; then - # Match the plugin block by name then check Status line. List is - # captured first: an early-exit awk/grep -q in a pipe SIGPIPEs the - # producer (rc 141 under pipefail on macOS). - local plist - plist="$("$CLAUDE_BIN" plugin list 2>/dev/null)" || true - if grep -q "✔ enabled" < <(awk -v p="$skill" ' - /^[[:space:]]*❯ '"$skill"'@/ { found=1; next } - found && /Status:/ { print; exit } - ' <<<"$plist"); then - echo "enabled" - else - echo "disabled" - fi - else - echo "unknown" - fi - ;; - mcp) - if command -v "$CLAUDE_BIN" >/dev/null 2>&1 && \ - grep -q "^${skill}" <<<"$("$CLAUDE_BIN" mcp list 2>/dev/null)"; then - echo "enabled" - else - echo "disabled" - fi - ;; - cli) - command -v "$skill" >/dev/null 2>&1 && echo "installed" || echo "not-installed" - ;; - *) echo "unknown" ;; - esac -} - -# How much of one profile is actually available right now. An item counts -# as available when its status is "enabled" (skills, plugins, MCPs) or -# "installed" (CLIs). Echo: " " — total 0 for an empty -# profile. Used by cmd_current to score the ACTIVE label only (BDR-030: -# scanning every profile for a best guess doesn't apply — gstack is off by -# default, so a parked count says nothing about which profile is on). -profile_match() { - local prof="$1" skill type status - local total=0 available=0 - while IFS=$'\t' read -r skill type; do - total=$((total + 1)) - status="$(skill_status "$skill" "$type")" - case "$status" in - enabled|installed) available=$((available + 1)) ;; - esac - done < <(read_profile "$prof") - printf '%d %d\n' "$available" "$total" -} - -# ── Enable / disable ────────────────────────────────────── - -# Enables a gstack skill: unpark it, or link it from the submodule. -enable_gstack_skill() { - local skill="$1" - if gstack_is_removed "$skill"; then - warn "refusing to enable removed skill: $skill (lib/gstack-removed.sh \ -— a profile census failure, not a crash)" - return 0 - elif [ -e "$DISABLED_DIR/gstack__$skill" ]; then - gstack_unpark "$SKILLS_DIR" "$DISABLED_DIR" "$skill" - ok "enabled: $skill" - elif [ -e "$DISABLED_DIR/$skill" ]; then - rm -rf "${SKILLS_DIR:?}/${skill:?}" - mv "$DISABLED_DIR/$skill" "$SKILLS_DIR/$skill" - ok "enabled: $skill" - elif [ -e "$SKILLS_DIR/$skill" ]; then - : # already enabled — silent - elif [ -d "$GSTACK_SRC/$skill" ]; then - # gstack is OFF by default: its skills live only in the submodule, - # never pre-symlinked into skills/. A profile that lists this gstack - # skill activates it on demand by symlinking the submodule skill dir - # in. disable_gstack_not_in() parks it again when an unrelated profile - # is set. The gstack/bin + browse/dist infra it relies on is created - # by link.sh, independent of this. - ln -sf "$GSTACK_SRC/$skill" "$SKILLS_DIR/$skill" - ok "enabled: $skill (gstack on-demand)" - elif [ ! -d "$GSTACK_SRC" ]; then - warn "missing: $skill — gstack submodule absent, run: git submodule update --init" - else - warn "missing: $skill — not found in gstack submodule ($GSTACK_SRC)" - fi -} - -# Enables an external|personal skill: unpark it, or recreate the symlink. -enable_linked_skill() { - local skill="$1" type="$2" - if [ -e "$DISABLED_DIR/$skill" ]; then - rm -rf "${SKILLS_DIR:?}/${skill:?}" - mv "$DISABLED_DIR/$skill" "$SKILLS_DIR/$skill" - ok "enabled: $skill ($type)" - elif [ -e "$SKILLS_DIR/$skill" ]; then - : - elif [ "$type" = external ] && [ -d "$REPO/skills-external/$skill" ]; then - # Symlink never created (or hand-removed): recreate it from the - # vendored pack — mirrors toggle-external.sh's from-source path. - ln -sf "$REPO/skills-external/$skill" "$SKILLS_DIR/$skill" - ok "enabled: $skill (external, symlink created)" - else - warn "missing: $skill ($type)" - fi -} - -# Enables a plugin@ skill through the claude CLI. -enable_plugin_skill() { - local skill="$1" type="$2" - # type holds the marketplace: plugin@ - local marketplace="${type#plugin@}" - if [ "$(skill_status "$skill" "$type")" = "enabled" ]; then - : # already on - elif command -v "$CLAUDE_BIN" >/dev/null 2>&1; then - # CLI call stays inside the condition: a failing CLI must not abort - if grep -qiE "enabled|already" \ - <<<"$("$CLAUDE_BIN" plugin enable \ - "${skill}@${marketplace}" 2>&1)"; then - ok "enabled plugin: ${skill}@${marketplace}" - else - warn "could not enable plugin: ${skill}@${marketplace}" - fi - else - info "claude CLI not in PATH — manual: claude plugin enable ${skill}@${marketplace}" - fi -} - -enable_skill() { - local skill="$1" type="$2" - case "$type" in - gstack) enable_gstack_skill "$skill" ;; - external|personal) enable_linked_skill "$skill" "$type" ;; - plugin@*) enable_plugin_skill "$skill" "$type" ;; - plugin) - # No marketplace specified — purely advisory. - if [ "$(skill_status "$skill" plugin)" = "enabled" ]; then - : # already on - else - info "plugin '$skill' not enabled — run: claude plugin enable $skill@" - fi - ;; - mcp) - # Advisory only: MANAGED_MCPS is empty, nothing is auto-registered. - # Re-add a delegation branch here the day a profile owns an MCP server. - if [ "$(skill_status "$skill" mcp)" = "enabled" ]; then - : # already on - else - info "MCP '$skill' not registered — run: claude mcp add $skill -- " - fi - ;; - cli) - # CLIs install externally; we never auto-install. Just report status. - if command -v "$skill" >/dev/null 2>&1; then - : # installed — silent - else - info "CLI '$skill' not installed — install separately (npm/cargo/pipx)" - fi - ;; - esac -} - -disable_skill() { - local skill="$1" type="$2" - case "$type" in - gstack) - if [ -e "$SKILLS_DIR/$skill" ]; then - mkdir -p "$DISABLED_DIR" - gstack_park "$SKILLS_DIR" "$DISABLED_DIR" "$skill" - ok "disabled: $skill" - fi - ;; - external|personal) - if [ -e "$SKILLS_DIR/$skill" ]; then - mkdir -p "$DISABLED_DIR" - rm -rf "${DISABLED_DIR:?}/${skill:?}" - mv "$SKILLS_DIR/$skill" "$DISABLED_DIR/$skill" - ok "disabled: $skill ($type)" - fi - ;; - plugin@*) - local marketplace="${type#plugin@}" - local key="${skill}@${marketplace}" - # Defensive check against PROTECTED_PLUGINS (always-on). - local p - for p in "${PROTECTED_PLUGINS[@]}"; do - if [ "$key" = "$p" ]; then - warn "refusing to disable protected plugin: $key" - return 0 - fi - done - if [ "$(skill_status "$skill" "$type")" = "disabled" ]; then - : # already off - elif command -v "$CLAUDE_BIN" >/dev/null 2>&1; then - if grep -qiE "disabled|already" \ - <<<"$("$CLAUDE_BIN" plugin disable "$key" 2>&1)"; then - ok "disabled plugin: $key" - else - warn "could not disable plugin: $key" - fi - else - info "claude CLI not in PATH — manual: claude plugin disable $key" - fi - ;; - plugin) - info "plugin '$skill' — manual: claude plugin disable $skill@" - ;; - mcp) - info "MCP '$skill' — manual: claude mcp remove $skill" - ;; - cli) - : # never auto-uninstall CLIs - ;; - esac -} - -# ── Shared gstack operations ────────────────────────────── - -# Re-enable every gstack skill parked in skills-disabled/ (move gstack__* -# back into skills/), skipping a name lib/gstack-removed.sh denies (left -# parked — the policy line goes to stderr). Shared by cmd_reset and -# `gstack on`. Echoes the REAL restored count (skipped names excluded) on -# stdout so the caller can report it accurately; per-skill confirmations -# go to stderr so that count is the only thing captured with `$(...)`. -enable_all_gstack() { - local name restored=0 - [ -d "$DISABLED_DIR" ] || { echo 0; return 0; } - while IFS= read -r name; do - if gstack_is_removed "$name"; then - info "skipped (removed by policy, lib/gstack-removed.sh): $name" >&2 - continue - fi - gstack_unpark "$SKILLS_DIR" "$DISABLED_DIR" "$name" - ok "re-enabled: $name" >&2 - restored=$((restored + 1)) - done < <(gstack_parked_names "$DISABLED_DIR") - echo "$restored" -} - -# Disable gstack-origin skills not listed in the given profile. Shared by -# cmd_set and `gstack off`. Caller is responsible for validating the profile. -disable_gstack_not_in() { - local prof="$1" - local keep_file name - keep_file="$(mktemp)" - read_profile "$prof" | cut -f1 | sort -u > "$keep_file" - while read -r name; do - [ -n "$name" ] || continue - grep -qx "$name" "$keep_file" || disable_skill "$name" gstack - done < <(gstack_skills "$GSTACK_SRC" | sort -u) - rm -f "$keep_file" -} - -# Count gstack skills currently parked in skills-disabled/. -parked_gstack_count() { - [ -d "$DISABLED_DIR" ] || { echo 0; return 0; } - find "$DISABLED_DIR" -maxdepth 1 -name 'gstack__*' 2>/dev/null | wc -l | tr -d ' ' -} - -# ── `set` trim helpers — one per managed category ───────────── -# Each disables the managed items NOT listed in the given profile. Allowlist -# doctrine: only MANAGED_* entries are ever auto-disabled. - -disable_plugins_not_in() { - local prof="$1" keep_file p plugin_name marketplace - keep_file="$(mktemp)" - read_profile "$prof" \ - | awk -F'\t' '$2 ~ /^plugin@/ { sub(/^plugin@/, "", $2); print $1"@"$2 }' \ - | sort -u > "$keep_file" - for p in "${MANAGED_PLUGINS[@]}"; do - if ! grep -qx "$p" "$keep_file"; then - plugin_name="${p%@*}" - marketplace="${p#*@}" - disable_skill "$plugin_name" "plugin@${marketplace}" - fi - done - rm -f "$keep_file" -} - -disable_externals_not_in() { - local prof="$1" keep_file x - keep_file="$(mktemp)" - read_profile "$prof" | awk -F'\t' '$2 == "external" { print $1 }' \ - | sort -u > "$keep_file" - for x in "${MANAGED_EXTERNALS[@]}"; do - grep -qx "$x" "$keep_file" || disable_skill "$x" external - done - rm -f "$keep_file" -} - -disable_mcps_not_in() { - local prof="$1" keep_file s - keep_file="$(mktemp)" - read_profile "$prof" | awk -F'\t' '$2 == "mcp" { print $1 }' \ - | sort -u > "$keep_file" - for s in "${MANAGED_MCPS[@]}"; do - grep -qx "$s" "$keep_file" || disable_skill "$s" mcp - done - rm -f "$keep_file" -} - -# ── Commands ────────────────────────────────────────────── - -cmd_list() { - printf "%-9s %-13s %s\n" "PROFILE" "ITEMS" "DESCRIPTION" - printf "%-9s %-13s %s\n" "-------" "-----" "-----------" - local f name desc skills pl m c contents - for f in "$PROFILES_DIR"/*.profile; do - [ -f "$f" ] || continue - name="$(basename "$f" .profile)" - desc="$(profile_desc "$f")" - read -r skills pl m c <<<"$(count_profile "$name")" - contents="$(fmt_counts compact "$skills" "$pl" "$m" "$c")" - printf "%-9s %s %s\n" "$name" "$(rpad "$contents" 13)" "${desc:--}" - done -} - -# Snapshot of a profile's entries, claude-free: "" lines, -# canonical name. A plugin's marketplace (plugin@) collapses to the -# category "plugin". -_show_entries() { - local skill type cat - while IFS=$'\t' read -r skill type; do - case "$type" in plugin@*|plugin) cat=plugin ;; *) cat="$type" ;; esac - printf '%s\t%s\n' "$cat" "$skill" - done < <(read_profile "$1") -} - -# --plain: parsable contract for the design gate. One "" -# per line, grouped by type, NO status, NO claude calls. -_show_plain() { - local entries=() cat e line - while IFS= read -r line; do entries+=("$line"); done < <(_show_entries "$1") - for cat in gstack external personal plugin mcp cli; do - for e in "${entries[@]}"; do - [ "${e%%$'\t'*}" = "$cat" ] && printf '%s\t%s\n' "$cat" "${e#*$'\t'}" - done - done - return 0 -} - -# Grouped by type, fixed order; empty groups skipped. Canonical name + -# runtime status (existing skill_status — degrades to disabled if no claude). -_show_grouped() { - local entries=() cat e line names skill status - while IFS= read -r line; do entries+=("$line"); done < <(_show_entries "$1") - for cat in gstack external personal plugin mcp cli; do - names=() - for e in "${entries[@]}"; do - [ "${e%%$'\t'*}" = "$cat" ] && names+=("${e#*$'\t'}") - done - [ "${#names[@]}" -eq 0 ] && continue - printf '%s (%d):\n' "$cat" "${#names[@]}" - for skill in "${names[@]}"; do - status="$(skill_status "$skill" "$cat")" - printf ' %-24s %s\n' "$skill" "$status" - done - done - return 0 -} - -cmd_show() { - local prof="$1" plain=0 - [ "${2:-}" = "--plain" ] && plain=1 - local file="$PROFILES_DIR/$prof.profile" - [ -f "$file" ] || { err "Profile not found: $prof"; return 1; } - - if [ "$plain" -eq 1 ]; then - _show_plain "$prof" - return 0 - fi - - echo "Profile: $prof" - local desc; desc="$(profile_desc "$file")" - [ -n "$desc" ] && echo "Description: $desc" - local skills pl m c total - read -r skills pl m c <<<"$(count_profile "$prof")" - total=$((skills + pl + m + c)) - if [ "$total" -eq 0 ]; then - echo "Total: 0 items (empty — strips all gstack)" - else - echo "Total: $total items — $(fmt_counts long "$skills" "$pl" "$m" "$c")" - fi - echo "" - - _show_grouped "$prof" -} - -cmd_apply() { - local prof="$1" - info "Applying profile: $prof (additive — leaves other skills alone)" - local skill type - while IFS=$'\t' read -r skill type; do - enable_skill "$skill" "$type" - done < <(read_profile "$prof") - write_active "$prof" -} - -cmd_set() { - local prof="$1" - info "Setting profile: $prof (exclusive — disables non-listed gstack skills + managed plugins/externals/MCPs)" - - # Disable gstack-origin skills not in profile. - disable_gstack_not_in "$prof" - - # Disable managed plugins not in profile (PROTECTED_PLUGINS are excluded - # by disable_skill itself — belt and suspenders). - disable_plugins_not_in "$prof" - - # Symmetry (BDR-079): a profile switch also parks the managed external - # packs and unregisters the managed MCPs the new profile does not need — - # design leftovers (emil, the 21st pack…) no longer survive a `set backend`. - disable_externals_not_in "$prof" - disable_mcps_not_in "$prof" - - # Enable everything listed in the profile. - cmd_apply "$prof" -} - -cmd_reset() { - info "Resetting to the default profile: $DEFAULT_PROFILE (exclusive — enables its list, parks any non-listed gstack or managed item currently on)" - cmd_set "$DEFAULT_PROFILE" -} - -# gstack on|off — focused gstack-only toggle that keeps the active-profile -# label intact (unlike reset, which switches to the default profile). Lets -# the user layer all gstack on top of their current profile, or trim it -# back down to just what the active profile needs. -cmd_gstack() { - local action="${1:-}" - case "$action" in - on) - # Restore whatever is parked, but DON'T touch active-profile — the - # user is adding gstack on top of their current profile, not clearing it. - local parked restored - parked="$(parked_gstack_count)" - if [ "$parked" -eq 0 ]; then - info "nothing parked — gstack skills are linked per profile (set/apply/reset)" - else - restored="$(enable_all_gstack)" - ok "$restored parked gstack skills restored" - fi - ;; - off) - # Disable gstack skills not needed by the active profile. A cache - # naming a profile with no lib/profiles/.profile still errors; - # absent/empty/"none" resolve to the default profile via - # active_profile() and no longer hit that error. - local active - active="$(active_profile)" - if [ ! -f "$PROFILES_DIR/$active.profile" ]; then - err "no active profile — 'gstack off' needs one to know what to keep" - info "run: bash lib/profile.sh set then: gstack off" - return 1 - fi - info "Disabling gstack skills not in active profile: $active" - disable_gstack_not_in "$active" - ok "gstack trimmed to profile: $active" - ;; - ""|-h|--help|help) - cat <<'EOF' -profile gstack on|off — toggle gstack without losing the active-profile label - - on re-enable ALL gstack skills (keeps active-profile label) - off disable gstack skills not in the active profile -EOF - ;; - *) - err "Unknown gstack action: '$action' (use: on | off)"; return 1 ;; - esac -} - -cmd_current() { - # Label-driven (BDR-030): name active_profile() and score ONLY that - # profile — no cross-profile best-guess scan, no fast path keyed on the - # parked-gstack count (that count says nothing about which profile is on - # when gstack starts off, as it does on a real tree). - local label; label="$(active_profile)" - if [ ! -f "$PROFILES_DIR/$label.profile" ]; then - echo "$label (unknown profile — no lib/profiles/$label.profile; run: profile reset)" - return 0 - fi - - local available total pct - read -r available total <<<"$(profile_match "$label")" - pct=0 - [ "$total" -gt 0 ] && pct=$((available * 100 / total)) - local parked; parked="$(parked_gstack_count)" - - local cached; cached="$(read_cache)" - if [ -z "$cached" ] || [ "$cached" = "none" ]; then - echo "$label (default — not applied yet, ${pct}% of its items enabled; run: profile reset)" - else - echo "$label (${pct}% match, $parked gstack skills disabled)" - fi -} - -cmd_diff() { - local a="$1" b="$2" - local fa="$PROFILES_DIR/$a.profile" fb="$PROFILES_DIR/$b.profile" - [ -f "$fa" ] || { err "Profile not found: $a"; return 1; } - [ -f "$fb" ] || { err "Profile not found: $b"; return 1; } - local list_a list_b - list_a="$(mktemp)"; list_b="$(mktemp)" - read_profile "$a" | cut -f1 | sort -u > "$list_a" - read_profile "$b" | cut -f1 | sort -u > "$list_b" - echo "Only in $a:"; comm -23 "$list_a" "$list_b" | sed 's/^/ - /' - echo "Only in $b:"; comm -13 "$list_a" "$list_b" | sed 's/^/ + /' - echo "Common:" ; comm -12 "$list_a" "$list_b" | sed 's/^/ = /' - rm -f "$list_a" "$list_b" -} +SKILLS_DIR="$REPO/skills" +STATE_JQ="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)/profile-state.jq" +USER_SETTINGS="${PROFILE_USER_SETTINGS:-$HOME/.claude/settings.json}" +CLAUDE_JSON="${PROFILE_CLAUDE_JSON:-$HOME/.claude.json}" +LOCAL_REL=".claude/settings.local.json" +PROJECT="$PWD" +die() { echo "profile: $*" >&2; exit 2; } usage() { - cat < show profile contents grouped by type + status - profile show --plain parsable type+name list (no status, no claude) - profile current report the active profile (label + match) - profile apply enable skills in profile (additive) - profile set enable only listed skills (disables rest of gstack) - profile reset go to the default profile (full): enable its list, - park non-listed gstack/managed items - profile gstack on|off toggle gstack only, keep active-profile label - profile diff compare two profiles - -PROFILES (in $PROFILES_DIR): -EOF - local f name desc - for f in "$PROFILES_DIR"/*.profile; do - [ -f "$f" ] || continue - name="$(basename "$f" .profile)" - desc="$(profile_desc "$f")" - printf " %-10s %s\n" "$name" "${desc:--}" - done - cat <" yourself. -EOF + sed -n '/^# Usage:/,/^#$/p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,2\}//' >&2 + exit 2 } -main() { - local cmd="${1:-}" - case "$cmd" in - list) cmd_list ;; - show) [ $# -ge 2 ] || { usage; exit 1; }; cmd_show "$2" "${3:-}" ;; - current) cmd_current ;; - apply) [ $# -ge 2 ] || { usage; exit 1; }; cmd_apply "$2" ;; - set) [ $# -ge 2 ] || { usage; exit 1; }; cmd_set "$2" ;; - reset) cmd_reset ;; - gstack) cmd_gstack "${2:-}" ;; - diff) [ $# -ge 3 ] || { usage; exit 1; }; cmd_diff "$2" "$3" ;; - ""|-h|--help|help) usage ;; - *) err "Unknown command: $cmd"; usage; exit 1 ;; +# ---- project root ---------------------------------------------------------- +find_root() { # $1 dir → nearest ancestor with .claude/, CLAUDE.md or .git + local d="$1" # the walk stops below $HOME: ~/.claude is not a project + while [ "$d" != / ] && [ "$d" != "$HOME" ]; do + if [ -d "$d/.claude" ] || [ -f "$d/CLAUDE.md" ] || [ -e "$d/.git" ]; then + echo "$d"; return 0 + fi + d="$(dirname "$d")" + done + echo "$1" +} +require_project_root() { + [ -f "$PROJECT/CLAUDE.md" ] || [ -e "$PROJECT/.git" ] \ + || die "not a project root (no CLAUDE.md and no .git): $PROJECT" +} + +# ---- inputs ---------------------------------------------------------------- +profile_file() { echo "$PROFILES_DIR/$1.json"; } +profile_names() { + local f + for f in "$PROFILES_DIR"/*.json; do [ -f "$f" ] && basename "$f" .json; done + return 0 +} +profile_desc() { # the `- **name**: text` line of lib/profiles/README.md + sed -n "s/^- \*\*$1\*\*: //p" "$PROFILES_DIR/README.md" 2>/dev/null | head -1 +} +managed_ids() { + jq -r '.enabledPlugins | keys[]' "$PROFILES_DIR"/*.json | sort -u +} +managed_connectors() { + jq -r '(.deniedMcpServers // [])[] | .serverName' "$PROFILES_DIR"/*.json \ + | sort -u +} +as_json_list() { jq -Rn '[inputs]'; } # stdin lines → JSON string array +json_or_empty() { # $1 file → its JSON, {} when absent; rc 2 when invalid + [ -f "$1" ] || { echo '{}'; return 0; } + jq -c . "$1" 2>/dev/null || return 2 +} +read_local() { + json_or_empty "$PROJECT/$LOCAL_REL" \ + || die "$LOCAL_REL is not valid JSON — nothing written" +} +pack_default() { # $1 id → true | false | missing (manifest defaultEnabled) + local m="$SKILLS_DIR/${1%@skills-dir}/.claude-plugin/plugin.json" + [ -f "$m" ] || { echo missing; return 0; } + jq -r 'if .defaultEnabled == false then "false" else "true" end' "$m" +} +manifests_json() { # [{id, on}] for every pack manifest, [] when none + jq -cn '[inputs | {id: (.name + "@skills-dir"), + on: (.defaultEnabled != false)}]' \ + "$SKILLS_DIR"/pack-*/.claude-plugin/plugin.json 2>/dev/null || echo '[]' +} +have_flag() { + [ -n "${CLAUDE_PROFILE_SETTINGS:-}" ] && [ -f "$CLAUDE_PROFILE_SETTINGS" ] +} +raw_or_null() { # $1 file → the path, or /dev/null when absent or unset + if [ -n "$1" ] && [ -f "$1" ]; then echo "$1"; else echo /dev/null; fi +} + +# ---- effective state: two jq calls ----------------------------------------- +state() { # $1 mode: plain | human | json + local hasflag=0; have_flag && hasflag=1 + jq -rn --arg mode "$1" --arg proj "$PROJECT" --arg hasflag "$hasflag" \ + --arg flagname "${CLAUDE_PROFILE:--}" \ + --rawfile u "$(raw_or_null "$USER_SETTINGS")" \ + --rawfile p "$(raw_or_null "$PROJECT/.claude/settings.json")" \ + --rawfile l "$(raw_or_null "$PROJECT/$LOCAL_REL")" \ + --rawfile f "$(raw_or_null "${CLAUDE_PROFILE_SETTINGS:-}")" \ + --rawfile cj "$(raw_or_null "$CLAUDE_JSON")" \ + --argjson m "$(manifests_json)" -f "$STATE_JQ" "$PROFILES_DIR"/*.json +} + +# ---- commands --------------------------------------------------------------- +unknown_profile() { + echo "profile: unknown profile '$1'. Known:" >&2; cmd_list >&2; exit 2 +} +cmd_list() { + local n d + for n in $(profile_names); do + d="$(profile_desc "$n")" + printf '%-10s %s\n' "$n" "${d:-(no line in lib/profiles/README.md)}" + done +} +cmd_show() { + local f id v tag + f="$(profile_file "$1")"; [ -f "$f" ] || unknown_profile "$1" + echo "profile $1: $(profile_desc "$1")" + for id in $(jq -r '.enabledPlugins | keys[]' "$f"); do + v="$(jq -r --arg k "$id" '.enabledPlugins[$k] + | if . then "on" else "off" end' "$f")" + tag="" + case "$id" in pack-*@skills-dir) + [ "$(pack_default "$id")" = missing ] \ + && tag=" missing (no skills/${id%@skills-dir}/)" ;; + esac + printf ' %-42s %s%s\n' "$id" "$v" "$tag" + done + echo " connectors denied: $(jq -r '(.deniedMcpServers // []) + | if length == 0 then "none" else map(.serverName) | join(", ") end' "$f")" + echo " model: $(jq -r '.model // "-"' "$f")" +} +cmd_current() { + if [ "${1:-}" = "--plain" ]; then state plain; else state human; fi +} +write_local() { # $1 JSON → atomic replace of the local settings + local tmp + mkdir -p "$PROJECT/.claude" + tmp="$(mktemp "$PROJECT/.claude/.settings.local.XXXXXX")" + jq . <<<"$1" > "$tmp" && mv -f "$tmp" "$PROJECT/$LOCAL_REL" +} +after_write_hint() { + echo "next: /reload-plugins loads the packs in this session;" \ + "connectors and model apply to the next session" + if have_flag; then + echo "note: this conversation runs --settings ${CLAUDE_PROFILE:-?}:" \ + "a pack it turns off stays off here — relaunch: cc " + fi +} +cmd_set() { + local f cur new + f="$(profile_file "$1")"; [ -f "$f" ] || unknown_profile "$1" + require_project_root; cur="$(read_local)" + new="$(jq --argjson cur "$cur" \ + --argjson names "$(managed_connectors | as_json_list)" ' + . as $p | $cur + | .enabledPlugins = (($cur.enabledPlugins // {}) + $p.enabledPlugins) + | .deniedMcpServers = ([($cur.deniedMcpServers // [])[] + | select(.serverName as $s | ($names | index($s)) == null)] + + ($p.deniedMcpServers // [])) + | if (.deniedMcpServers | length) == 0 then del(.deniedMcpServers) + else . end + | if $p.model then .model = $p.model else . end' "$f")" + write_local "$new" + echo "profile $1 → $LOCAL_REL"; after_write_hint +} +cmd_unset() { + local cur name pm new + require_project_root; cur="$(read_local)" + name="$(CLAUDE_PROFILE_SETTINGS='' state json | jq -r .name)" + pm="-" + [ "$name" != custom ] \ + && pm="$(jq -r '.model // "-"' "$(profile_file "$name")")" + new="$(jq --argjson ids "$(managed_ids | as_json_list)" \ + --argjson names "$(managed_connectors | as_json_list)" --arg pm "$pm" ' + .enabledPlugins = ((.enabledPlugins // {}) + | with_entries(select(.key as $k | ($ids | index($k)) == null))) + | if (.enabledPlugins | length) == 0 then del(.enabledPlugins) else . end + | .deniedMcpServers = [(.deniedMcpServers // [])[] + | select(.serverName as $s | ($names | index($s)) == null)] + | if (.deniedMcpServers | length) == 0 then del(.deniedMcpServers) + else . end + | if $pm != "-" and .model == $pm then del(.model) else . end' <<<"$cur")" + write_local "$new" + echo "profile keys removed from $LOCAL_REL (was: $name)"; after_write_hint +} +resolve_id() { # design | pack-design | pack-design@skills-dir | + case "$1" in + *@*) echo "$1" ;; + pack-*) echo "$1@skills-dir" ;; + *) echo "pack-$1@skills-dir" ;; esac } +cmd_toggle() { # $1 true|false, $2 pack or plugin spelling + local id cur new + id="$(resolve_id "$2")" + managed_ids | grep -qx -- "$id" \ + || die "unknown pack or plugin '$2' (known: $(managed_ids | tr '\n' ' '))" + require_project_root; cur="$(read_local)" + new="$(jq --arg id "$id" --argjson v "$1" \ + '.enabledPlugins = ((.enabledPlugins // {}) + {($id): $v})' <<<"$cur")" + write_local "$new" + echo "$id=$1 → $LOCAL_REL"; after_write_hint +} +cmd_diff() { + local f out + f="$(profile_file "$1")"; [ -f "$f" ] || unknown_profile "$1" + out="$(jq -r --argjson e "$(state json)" ' + def onoff: if . then "on" else "off" end; + (.enabledPlugins | to_entries[] | select($e.plugins[.key] != .value) + | .key + ": " + ($e.plugins[.key] | onoff) + " → " + (.value | onoff)), + (([(.deniedMcpServers // [])[] | .serverName] | sort) as $want + | ($e.denied | sort) as $have + | if $want == $have then empty + else "connectors denied: " + ($have | join(", ")) + " → " + + ($want | join(", ")) end), + (if (.model // "-") != $e.model + then "model: " + $e.model + " → " + (.model // "-") + else empty end)' "$f")" + if [ -n "$out" ]; then echo "$out"; else echo "no difference from $1"; fi +} -main "$@" +# ---- main -------------------------------------------------------------------- +command -v jq >/dev/null 2>&1 || die "jq is required" +while [ $# -gt 0 ]; do + case "$1" in + -C) [ -n "${2:-}" ] || usage + PROJECT="$(cd "$2" 2>/dev/null && pwd)" || die "no such dir: $2" + shift 2 ;; + *) break ;; + esac +done +PROJECT="$(find_root "$PROJECT")" +case "${1:-}" in + list) cmd_list ;; + show) [ -n "${2:-}" ] || usage; cmd_show "$2" ;; + current) cmd_current "${2:-}" ;; + set) [ -n "${2:-}" ] || usage; cmd_set "$2" ;; + unset) cmd_unset ;; + enable) [ -n "${2:-}" ] || usage; cmd_toggle true "$2" ;; + disable) [ -n "${2:-}" ] || usage; cmd_toggle false "$2" ;; + diff) [ -n "${2:-}" ] || usage; cmd_diff "$2" ;; + *) usage ;; +esac diff --git a/lib/profiles/README.md b/lib/profiles/README.md new file mode 100644 index 0000000..1accedb --- /dev/null +++ b/lib/profiles/README.md @@ -0,0 +1,34 @@ +# Profiles + +A profile is a literal Claude Code settings fragment: `enabledPlugins` +(every pack `pack-@skills-dir` and managed plugin, explicit), optional +`deniedMcpServers` (the two higgsfield claude.ai connectors), optional +`model`. Per project: `bash ~/.claude/lib/profile.sh set ` writes it +into `.claude/settings.local.json`, then `/reload-plugins`. Per +conversation: `cc ` (lib/cc.sh) runs +`claude --settings lib/profiles/.json`; that conversation is frozen +(no reload brings a pack back; relaunch instead). No profile = the manifest +defaults = `full` with the connectors present. `deniedMcpServers` is a union +across files: a `cc x web` over a project set to `dev` keeps the connectors +denied; `set web` in the project brings them back next session. + +`profile.sh list` reads these lines (format `- **name**: text`): + +- **full**: every pack except higgsfield and extras; ui-ux-pro-max on; connectors present. The default. +- **max**: everything on, pr-review-toolkit included; for a one-off session, not a project. +- **minimal**: no pack, no design plugin, connectors denied; the smallest listing. +- **dev**: gstack-dev only; backend or tooling work without UI. +- **backend**: same packs as dev; kept as a name for backend projects. +- **design**: design, scroll3d, gstack-design, gstack-browser, ui-ux-pro-max; connectors present. +- **web**: design + scroll3d + web-validate + the three gstack packs + ui-ux-pro-max; public site work. +- **web-full**: web + seo; a site with SEO/GEO on top. +- **seo**: seo, web-validate, gstack-browser, gstack-dev; audit and fixes on a live site. +- **qa**: gstack-browser + web-validate; dogfooding and conformance only. +- **audit**: seo, web-validate, gstack-dev, gstack-browser, pr-review-toolkit; read-mostly audits. + +Invariants (checked by `lib/pack-census.sh`): the same key set in every +fragment; `model-router@skills-dir` and `security-guidance@claude-code-plugins` +true everywhere; `example-skills@anthropic-agent-skills` and +`brightdata-plugin@synced` false everywhere; the connectors denied on exactly +minimal, dev, backend, seo, qa, audit; `full` equal to the manifest defaults. +Add your own profile as another `.json` with the same key set. diff --git a/lib/profiles/audit.json b/lib/profiles/audit.json new file mode 100644 index 0000000..30ccb0f --- /dev/null +++ b/lib/profiles/audit.json @@ -0,0 +1,27 @@ +{ + "enabledPlugins": { + "model-router@skills-dir": true, + "pack-design@skills-dir": false, + "pack-scroll3d@skills-dir": false, + "pack-seo@skills-dir": true, + "pack-web-validate@skills-dir": true, + "pack-gstack-dev@skills-dir": true, + "pack-gstack-browser@skills-dir": true, + "pack-gstack-design@skills-dir": false, + "pack-higgsfield@skills-dir": false, + "pack-extras@skills-dir": false, + "ui-ux-pro-max@ui-ux-pro-max-skill": false, + "security-guidance@claude-code-plugins": true, + "pr-review-toolkit@claude-code-plugins": true, + "example-skills@anthropic-agent-skills": false, + "brightdata-plugin@synced": false + }, + "deniedMcpServers": [ + { + "serverName": "claude.ai higgsfield" + }, + { + "serverName": "claude.ai Higgsfield AI" + } + ] +} diff --git a/lib/profiles/audit.profile b/lib/profiles/audit.profile deleted file mode 100644 index 61d8602..0000000 --- a/lib/profiles/audit.profile +++ /dev/null @@ -1,30 +0,0 @@ -# DESC: Comprehensive audit — security + SEO + GEO + W3C + perf + health -# Activate when: doing a top-to-bottom audit pass on an existing project. -# Wider than `seo` (adds security + dependency review). - -# Security -cso -harden personal -guardrails personal -a11y personal -analyze personal - -# SEO / GEO / web standards -seo personal -geo personal -web-validate personal - -# Code + perf health -health -benchmark -review - -# Browser tooling for live audits -browse -open-gstack-browser - -# Plugin: PR review toolkit (audit context for diffs) -pr-review-toolkit plugin@claude-code-plugins - -# CLI: graphify for code structure -graphify cli diff --git a/lib/profiles/backend.json b/lib/profiles/backend.json new file mode 100644 index 0000000..829bef0 --- /dev/null +++ b/lib/profiles/backend.json @@ -0,0 +1,27 @@ +{ + "enabledPlugins": { + "model-router@skills-dir": true, + "pack-design@skills-dir": false, + "pack-scroll3d@skills-dir": false, + "pack-seo@skills-dir": false, + "pack-web-validate@skills-dir": false, + "pack-gstack-dev@skills-dir": true, + "pack-gstack-browser@skills-dir": false, + "pack-gstack-design@skills-dir": false, + "pack-higgsfield@skills-dir": false, + "pack-extras@skills-dir": false, + "ui-ux-pro-max@ui-ux-pro-max-skill": false, + "security-guidance@claude-code-plugins": true, + "pr-review-toolkit@claude-code-plugins": false, + "example-skills@anthropic-agent-skills": false, + "brightdata-plugin@synced": false + }, + "deniedMcpServers": [ + { + "serverName": "claude.ai higgsfield" + }, + { + "serverName": "claude.ai Higgsfield AI" + } + ] +} diff --git a/lib/profiles/backend.profile b/lib/profiles/backend.profile deleted file mode 100644 index a59697f..0000000 --- a/lib/profiles/backend.profile +++ /dev/null @@ -1,44 +0,0 @@ -# DESC: Backend / API / system dev — no design, no SEO, focused on logic -# Activate when: building backend services, APIs, CLIs, libraries, system -# code, data pipelines. UI/visual work is out of scope. SEO/GEO out of scope. - -# Code work — primary -feat personal -ship-feature personal -hotfix personal -bugfix personal -investigate -refactor personal -code-clean personal -commit-change personal -analyze personal - -# Dev-lifecycle skills (agent-skills trio) -observability-and-instrumentation external -deprecation-and-migration external -ci-cd-and-automation external - -# Review -review - -# Second opinion for hard problems -codex - -# Security + health (always relevant for backend) -cso -guardrails personal -health - -# Session hygiene -freeze -unfreeze -retro - -# pr-review-toolkit removed (audit 2026-07-02 #12 — ~2.2k tokens, PR-only): -# enable per PR session via `bash lib/profile.sh apply audit` or -# claude plugin enable pr-review-toolkit@claude-code-plugins - -# CLIs (advisory) -ctx7 cli -gsd cli -graphify cli diff --git a/lib/profiles/design.json b/lib/profiles/design.json new file mode 100644 index 0000000..736c146 --- /dev/null +++ b/lib/profiles/design.json @@ -0,0 +1,19 @@ +{ + "enabledPlugins": { + "model-router@skills-dir": true, + "pack-design@skills-dir": true, + "pack-scroll3d@skills-dir": true, + "pack-seo@skills-dir": false, + "pack-web-validate@skills-dir": false, + "pack-gstack-dev@skills-dir": false, + "pack-gstack-browser@skills-dir": true, + "pack-gstack-design@skills-dir": true, + "pack-higgsfield@skills-dir": false, + "pack-extras@skills-dir": false, + "ui-ux-pro-max@ui-ux-pro-max-skill": true, + "security-guidance@claude-code-plugins": true, + "pr-review-toolkit@claude-code-plugins": false, + "example-skills@anthropic-agent-skills": false, + "brightdata-plugin@synced": false + } +} diff --git a/lib/profiles/design.profile b/lib/profiles/design.profile deleted file mode 100644 index dc20f40..0000000 --- a/lib/profiles/design.profile +++ /dev/null @@ -1,55 +0,0 @@ -# DESC: Design work — visual QA, design systems, mockups, polish -# Activate when: building/reviewing UI, picking aesthetics, design tokens. -# Companion CLIs (advisory): graphify (visual structure). -# -# Gate scope (design-tool-gate.sh): only the tools on the GATE-BLOCK lines -# below trip the design gate. The rest of this profile (browser/plan/shotgun -# tooling, graphify) is bundled for convenience but never blocks. Keep these -# lines in sync when adding/removing a core design tool. -# GATE-BLOCK: impeccable ui-ux-pro-max emil-design-eng design-html -# GATE-BLOCK: design-motion-principles design-review design-consultation -# GATE-BLOCK: 21st 21st-ui-build - -# Core design skills (gstack) -design-review -design-consultation -design-html -plan-design-review - -# Browser tooling — design-review relies on it -browse -open-gstack-browser -setup-browser-cookies - -# Plan-mode review companion (taste decisions before code) -plan-ceo-review - -# External: design skills -emil-design-eng external -frontend-design external -design-motion-principles external -impeccable external - -# External: Mengto scroll-choreography skills (curl, commit-pinned) -scroll-world-storytelling external -build-threejs-scroll-worlds external -scroll-scrubbed-visual-sequence external -scroll-scrubbed-word-reveal external -scroll-progress-timeline external - -# Personal: motion implementation companion (skills/site-motion) -site-motion personal - -# External: 21st.dev pack — CLI-driven (no MCP, no API key). 21st-registry -# and 21st-design-sync are publishing flows; installed but left parked. -21st-ui-build external -21st-cli-use external - -# Plugin (auto-toggle) -ui-ux-pro-max plugin@ui-ux-pro-max-skill - -# CLIs (advisory only — installed/not-installed) -# 21st is NOT advisory: it is on the GATE-BLOCK list, so a missing CLI trips -# the design gate. Install: npm i -g @21st-dev/cli then 21st login -21st cli -graphify cli diff --git a/lib/profiles/dev.json b/lib/profiles/dev.json new file mode 100644 index 0000000..829bef0 --- /dev/null +++ b/lib/profiles/dev.json @@ -0,0 +1,27 @@ +{ + "enabledPlugins": { + "model-router@skills-dir": true, + "pack-design@skills-dir": false, + "pack-scroll3d@skills-dir": false, + "pack-seo@skills-dir": false, + "pack-web-validate@skills-dir": false, + "pack-gstack-dev@skills-dir": true, + "pack-gstack-browser@skills-dir": false, + "pack-gstack-design@skills-dir": false, + "pack-higgsfield@skills-dir": false, + "pack-extras@skills-dir": false, + "ui-ux-pro-max@ui-ux-pro-max-skill": false, + "security-guidance@claude-code-plugins": true, + "pr-review-toolkit@claude-code-plugins": false, + "example-skills@anthropic-agent-skills": false, + "brightdata-plugin@synced": false + }, + "deniedMcpServers": [ + { + "serverName": "claude.ai higgsfield" + }, + { + "serverName": "claude.ai Higgsfield AI" + } + ] +} diff --git a/lib/profiles/dev.profile b/lib/profiles/dev.profile deleted file mode 100644 index 300b4e0..0000000 --- a/lib/profiles/dev.profile +++ /dev/null @@ -1,27 +0,0 @@ -# DESC: Daily code work — small features, fixes, refactor, ship (any stack) -# Activate when: implementing features, debugging, shipping PRs without a -# specific frontend or backend bias. Lighter than `backend` (no security audit -# baggage) and lighter than `web` (no design pipeline). - -# Implementation -feat personal -ship-feature personal - -# Bug fixing -hotfix personal -bugfix personal -investigate - -# Code health -review -refactor personal -code-clean personal -commit-change personal -explain-diff personal -guardrails personal -a11y personal - -# Dev-lifecycle skills (agent-skills trio) -observability-and-instrumentation external -deprecation-and-migration external -ci-cd-and-automation external diff --git a/lib/profiles/full.json b/lib/profiles/full.json new file mode 100644 index 0000000..0aec36a --- /dev/null +++ b/lib/profiles/full.json @@ -0,0 +1,19 @@ +{ + "enabledPlugins": { + "model-router@skills-dir": true, + "pack-design@skills-dir": true, + "pack-scroll3d@skills-dir": true, + "pack-seo@skills-dir": true, + "pack-web-validate@skills-dir": true, + "pack-gstack-dev@skills-dir": true, + "pack-gstack-browser@skills-dir": true, + "pack-gstack-design@skills-dir": true, + "pack-higgsfield@skills-dir": false, + "pack-extras@skills-dir": false, + "ui-ux-pro-max@ui-ux-pro-max-skill": true, + "security-guidance@claude-code-plugins": true, + "pr-review-toolkit@claude-code-plugins": false, + "example-skills@anthropic-agent-skills": false, + "brightdata-plugin@synced": false + } +} diff --git a/lib/profiles/full.profile b/lib/profiles/full.profile deleted file mode 100644 index b792eef..0000000 --- a/lib/profiles/full.profile +++ /dev/null @@ -1,104 +0,0 @@ -# DESC: Default profile — carries everything every other profile carries -# (user rule 2026-09-28: full does what each profile does), minus the -# broken or doctrine-breaking gstack skills (lib/gstack-removed.sh) and -# the parked tools (make-pdf, diagram, 21st-ai/ui-explore/ui-review) that -# live in `max`. One named exception: pr-review-toolkit (see below). - -# === Brainstorm + plan-mode reviews ================================== -office-hours -plan-ceo-review -plan-eng-review -plan-design-review -plan-devex-review -spec - -# === Design pipeline ================================================= -design-review -design-consultation -design-html - -# === Browser + dogfooding ============================================ -browse -open-gstack-browser -setup-browser-cookies -scrape -skillify - -# === Code work — implementation ====================================== -feat personal -ship-feature personal -hotfix personal -bugfix personal -investigate -refactor personal -code-clean personal -commit-change personal - -# === Review =========================================================== -review - -# === Second opinion ================================================== -codex - -# === SEO / GEO / standards / security ================================ -seo personal -geo personal -web-validate personal -harden personal -guardrails personal -a11y personal -analyze personal -cso - -# === Perf + canary + QA ============================================== -health -benchmark -canary -qa -qa-only - -# === Docs + translation ============================================== -doc personal -document-release -pdf-translate personal -explain-diff personal - -# === Session hygiene + memory ======================================== -close personal -prune-memory personal -status personal -retro -freeze -unfreeze - -# === External + plugin + MCP ========================================= -emil-design-eng external -frontend-design external -design-motion-principles external -impeccable external -observability-and-instrumentation external -deprecation-and-migration external -ci-cd-and-automation external -scroll-world-storytelling external -build-threejs-scroll-worlds external -scroll-scrubbed-visual-sequence external -scroll-scrubbed-word-reveal external -scroll-progress-timeline external -ui-ux-pro-max plugin@ui-ux-pro-max-skill -# pr-review-toolkit REMOVED from full (audit 2026-07-02 #12): heaviest -# single plugin cost (~2.2k tokens of agent descriptions/session), useful -# only when reviewing PRs. Reactivate per PR session: -# claude plugin enable pr-review-toolkit@claude-code-plugins -# or profile-based: bash lib/profile.sh apply audit (audit.profile keeps it; -# a later `set full` re-disables it — MANAGED_PLUGINS lifecycle). -21st-ui-build external -21st-cli-use external - -# Personal: motion implementation companion (skills/site-motion) -site-motion personal - -# === CLIs (advisory) ================================================= -21st cli -ctx7 cli -graphify cli -gsd cli diff --git a/lib/profiles/max.json b/lib/profiles/max.json new file mode 100644 index 0000000..040c594 --- /dev/null +++ b/lib/profiles/max.json @@ -0,0 +1,19 @@ +{ + "enabledPlugins": { + "model-router@skills-dir": true, + "pack-design@skills-dir": true, + "pack-scroll3d@skills-dir": true, + "pack-seo@skills-dir": true, + "pack-web-validate@skills-dir": true, + "pack-gstack-dev@skills-dir": true, + "pack-gstack-browser@skills-dir": true, + "pack-gstack-design@skills-dir": true, + "pack-higgsfield@skills-dir": true, + "pack-extras@skills-dir": true, + "ui-ux-pro-max@ui-ux-pro-max-skill": true, + "security-guidance@claude-code-plugins": true, + "pr-review-toolkit@claude-code-plugins": true, + "example-skills@anthropic-agent-skills": false, + "brightdata-plugin@synced": false + } +} diff --git a/lib/profiles/max.profile b/lib/profiles/max.profile deleted file mode 100644 index 2792c78..0000000 --- a/lib/profiles/max.profile +++ /dev/null @@ -1,105 +0,0 @@ -# DESC: Everything — full + the parked generation/review tools + PR review -# SUPERSET-OF: full -# Activate when: you need make-pdf, diagram, the 21st-ai/ui-explore/ -# ui-review generation trio, or pr-review-toolkit, on top of everything -# full carries. Never a broken or doctrine-breaking gstack skill -# (lib/gstack-removed.sh) — max is full's superset, not the raw catalog. - -# === Brainstorm + plan-mode reviews ================================== -office-hours -plan-ceo-review -plan-eng-review -plan-design-review -plan-devex-review -spec - -# === Design pipeline ================================================= -design-review -design-consultation -design-html - -# === Browser + dogfooding ============================================ -browse -open-gstack-browser -setup-browser-cookies -scrape -skillify - -# === Code work — implementation ====================================== -feat personal -ship-feature personal -hotfix personal -bugfix personal -investigate -refactor personal -code-clean personal -commit-change personal - -# === Review =========================================================== -review - -# === Second opinion ================================================== -codex - -# === SEO / GEO / standards / security ================================ -seo personal -geo personal -web-validate personal -harden personal -guardrails personal -a11y personal -analyze personal -cso - -# === Perf + canary + QA ============================================== -health -benchmark -canary -qa -qa-only - -# === Docs + translation ============================================== -doc personal -document-release -diagram -make-pdf -pdf-translate personal -explain-diff personal - -# === Session hygiene + memory ======================================== -close personal -prune-memory personal -status personal -retro -freeze -unfreeze - -# === External + plugin + MCP ========================================= -emil-design-eng external -frontend-design external -design-motion-principles external -impeccable external -observability-and-instrumentation external -deprecation-and-migration external -ci-cd-and-automation external -scroll-world-storytelling external -build-threejs-scroll-worlds external -scroll-scrubbed-visual-sequence external -scroll-scrubbed-word-reveal external -scroll-progress-timeline external -ui-ux-pro-max plugin@ui-ux-pro-max-skill -pr-review-toolkit plugin@claude-code-plugins -21st-ui-build external -21st-ui-explore external -21st-ui-review external -21st-cli-use external -21st-ai external - -# Personal: motion implementation companion (skills/site-motion) -site-motion personal - -# === CLIs (advisory) ================================================= -21st cli -ctx7 cli -graphify cli -gsd cli diff --git a/lib/profiles/minimal.json b/lib/profiles/minimal.json new file mode 100644 index 0000000..d98652a --- /dev/null +++ b/lib/profiles/minimal.json @@ -0,0 +1,27 @@ +{ + "enabledPlugins": { + "model-router@skills-dir": true, + "pack-design@skills-dir": false, + "pack-scroll3d@skills-dir": false, + "pack-seo@skills-dir": false, + "pack-web-validate@skills-dir": false, + "pack-gstack-dev@skills-dir": false, + "pack-gstack-browser@skills-dir": false, + "pack-gstack-design@skills-dir": false, + "pack-higgsfield@skills-dir": false, + "pack-extras@skills-dir": false, + "ui-ux-pro-max@ui-ux-pro-max-skill": false, + "security-guidance@claude-code-plugins": true, + "pr-review-toolkit@claude-code-plugins": false, + "example-skills@anthropic-agent-skills": false, + "brightdata-plugin@synced": false + }, + "deniedMcpServers": [ + { + "serverName": "claude.ai higgsfield" + }, + { + "serverName": "claude.ai Higgsfield AI" + } + ] +} diff --git a/lib/profiles/minimal.profile b/lib/profiles/minimal.profile deleted file mode 100644 index fe4e0e2..0000000 --- a/lib/profiles/minimal.profile +++ /dev/null @@ -1,7 +0,0 @@ -# DESC: Strip all gstack skills (only essential personal skills + plugins remain) -# Activate when: you want a quiet session with no gstack noise. -# -# Empty by design — `profile set minimal` disables every gstack skill, -# leaves personal skills (analyze, doc, init-project, onboard, plugin-check, -# refactor, seo, validate, harden, etc.) untouched, and makes no plugin/MCP -# changes. To revert: `profile reset`. diff --git a/lib/profiles/qa.json b/lib/profiles/qa.json new file mode 100644 index 0000000..c8c7319 --- /dev/null +++ b/lib/profiles/qa.json @@ -0,0 +1,27 @@ +{ + "enabledPlugins": { + "model-router@skills-dir": true, + "pack-design@skills-dir": false, + "pack-scroll3d@skills-dir": false, + "pack-seo@skills-dir": false, + "pack-web-validate@skills-dir": true, + "pack-gstack-dev@skills-dir": false, + "pack-gstack-browser@skills-dir": true, + "pack-gstack-design@skills-dir": false, + "pack-higgsfield@skills-dir": false, + "pack-extras@skills-dir": false, + "ui-ux-pro-max@ui-ux-pro-max-skill": false, + "security-guidance@claude-code-plugins": true, + "pr-review-toolkit@claude-code-plugins": false, + "example-skills@anthropic-agent-skills": false, + "brightdata-plugin@synced": false + }, + "deniedMcpServers": [ + { + "serverName": "claude.ai higgsfield" + }, + { + "serverName": "claude.ai Higgsfield AI" + } + ] +} diff --git a/lib/profiles/qa.profile b/lib/profiles/qa.profile deleted file mode 100644 index 1158322..0000000 --- a/lib/profiles/qa.profile +++ /dev/null @@ -1,11 +0,0 @@ -# DESC: QA + testing — site checks, perf, canary, validation -# Activate when: running QA, checking deployed pages, perf regressions. - -qa -qa-only -browse -benchmark -canary -web-validate personal -open-gstack-browser -setup-browser-cookies diff --git a/lib/profiles/seo.json b/lib/profiles/seo.json new file mode 100644 index 0000000..0b93d92 --- /dev/null +++ b/lib/profiles/seo.json @@ -0,0 +1,27 @@ +{ + "enabledPlugins": { + "model-router@skills-dir": true, + "pack-design@skills-dir": false, + "pack-scroll3d@skills-dir": false, + "pack-seo@skills-dir": true, + "pack-web-validate@skills-dir": true, + "pack-gstack-dev@skills-dir": true, + "pack-gstack-browser@skills-dir": true, + "pack-gstack-design@skills-dir": false, + "pack-higgsfield@skills-dir": false, + "pack-extras@skills-dir": false, + "ui-ux-pro-max@ui-ux-pro-max-skill": false, + "security-guidance@claude-code-plugins": true, + "pr-review-toolkit@claude-code-plugins": false, + "example-skills@anthropic-agent-skills": false, + "brightdata-plugin@synced": false + }, + "deniedMcpServers": [ + { + "serverName": "claude.ai higgsfield" + }, + { + "serverName": "claude.ai Higgsfield AI" + } + ] +} diff --git a/lib/profiles/seo.profile b/lib/profiles/seo.profile deleted file mode 100644 index 09bb8b5..0000000 --- a/lib/profiles/seo.profile +++ /dev/null @@ -1,25 +0,0 @@ -# DESC: SEO + GEO + W3C audit — search/AI indexability + standards -# Activate when: auditing a site for Google/Bing indexability, AI search -# (ChatGPT/Perplexity/Claude/Gemini), W3C HTML/CSS validity, WCAG a11y. -# No design skills, no dev skills — pure audit pipeline. - -# SEO + GEO audits (personal) -seo personal -geo personal - -# W3C HTML/CSS validity + WCAG a11y -web-validate personal - -# Web hardening (HSTS, CSP, redirects — affects ranking signals) -harden personal - -# Code analysis (read structure for audit) -analyze personal - -# Browser tooling — needed for live-page audits -browse -open-gstack-browser - -# Health check + benchmark — Core Web Vitals, perf signals -health # gstack -benchmark # gstack diff --git a/lib/profiles/web-full.json b/lib/profiles/web-full.json new file mode 100644 index 0000000..0aec36a --- /dev/null +++ b/lib/profiles/web-full.json @@ -0,0 +1,19 @@ +{ + "enabledPlugins": { + "model-router@skills-dir": true, + "pack-design@skills-dir": true, + "pack-scroll3d@skills-dir": true, + "pack-seo@skills-dir": true, + "pack-web-validate@skills-dir": true, + "pack-gstack-dev@skills-dir": true, + "pack-gstack-browser@skills-dir": true, + "pack-gstack-design@skills-dir": true, + "pack-higgsfield@skills-dir": false, + "pack-extras@skills-dir": false, + "ui-ux-pro-max@ui-ux-pro-max-skill": true, + "security-guidance@claude-code-plugins": true, + "pr-review-toolkit@claude-code-plugins": false, + "example-skills@anthropic-agent-skills": false, + "brightdata-plugin@synced": false + } +} diff --git a/lib/profiles/web-full.profile b/lib/profiles/web-full.profile deleted file mode 100644 index 1c49fcf..0000000 --- a/lib/profiles/web-full.profile +++ /dev/null @@ -1,66 +0,0 @@ -# DESC: Production website — design + dev + SEO + GEO + W3C + perf -# Activate when: shipping a public website end-to-end. Combines `web` -# and `seo` profiles into a single set so the same session can build, -# polish, audit, and verify. - -# === Design =========================================================== -design-review -design-consultation -design-html -plan-design-review - -# === Browser + dogfooding ============================================= -browse -open-gstack-browser -setup-browser-cookies - -# === Plan-mode reviews ================================================ -plan-ceo-review -plan-eng-review -spec - -# === Code work ======================================================== -feat personal -ship-feature personal -hotfix personal -bugfix personal -review -commit-change personal -refactor personal - -# === SEO / GEO / standards =========================================== -seo personal -geo personal -web-validate personal -harden personal -guardrails personal -a11y personal -analyze personal - -# === Perf + canary =================================================== -health -benchmark -canary -qa-only - -# === External + plugin + MCP ========================================= -emil-design-eng external -frontend-design external -design-motion-principles external -impeccable external -scroll-world-storytelling external -build-threejs-scroll-worlds external -scroll-scrubbed-visual-sequence external -scroll-scrubbed-word-reveal external -scroll-progress-timeline external -21st-ui-build external -21st-cli-use external -ui-ux-pro-max plugin@ui-ux-pro-max-skill - -# Personal: motion implementation companion (skills/site-motion) -site-motion personal - -# === CLIs ============================================================ -21st cli -ctx7 cli -graphify cli diff --git a/lib/profiles/web.json b/lib/profiles/web.json new file mode 100644 index 0000000..97e48f0 --- /dev/null +++ b/lib/profiles/web.json @@ -0,0 +1,19 @@ +{ + "enabledPlugins": { + "model-router@skills-dir": true, + "pack-design@skills-dir": true, + "pack-scroll3d@skills-dir": true, + "pack-seo@skills-dir": false, + "pack-web-validate@skills-dir": true, + "pack-gstack-dev@skills-dir": true, + "pack-gstack-browser@skills-dir": true, + "pack-gstack-design@skills-dir": true, + "pack-higgsfield@skills-dir": false, + "pack-extras@skills-dir": false, + "ui-ux-pro-max@ui-ux-pro-max-skill": true, + "security-guidance@claude-code-plugins": true, + "pr-review-toolkit@claude-code-plugins": false, + "example-skills@anthropic-agent-skills": false, + "brightdata-plugin@synced": false + } +} diff --git a/lib/profiles/web.profile b/lib/profiles/web.profile deleted file mode 100644 index 7d32538..0000000 --- a/lib/profiles/web.profile +++ /dev/null @@ -1,62 +0,0 @@ -# DESC: Public website work — frontend + content + light dev -# Activate when: building/iterating a public-facing website (landing, -# portfolio, marketing, blog) where SEO is NOT the immediate focus. -# For SEO/GEO audit on top, use web-full or apply seo afterwards. - -# Design skills (gstack) — full design pipeline -design-review -design-consultation -design-html -plan-design-review - -# Browser tooling for design + dogfooding -browse -open-gstack-browser -setup-browser-cookies - -# Plan-mode reviews relevant to web work -plan-ceo-review -plan-eng-review - -# Code work skills — needed to actually build the site -feat personal -ship-feature personal -hotfix personal -review # gstack -commit-change personal -refactor personal - -# Validation companion (basic W3C/a11y check during build) -web-validate personal -a11y personal - -# External: design skills -emil-design-eng external -frontend-design external -design-motion-principles external -impeccable external - -# External: Mengto scroll-choreography skills (curl, commit-pinned) -scroll-world-storytelling external -build-threejs-scroll-worlds external -scroll-scrubbed-visual-sequence external -scroll-scrubbed-word-reveal external -scroll-progress-timeline external - -# Personal: motion implementation companion (skills/site-motion) -site-motion personal - -# External: 21st.dev pack (publishing flows 21st-registry / -design-sync -# stay parked) -21st-ui-build external -21st-cli-use external - -# Plugin: UI/UX intelligence (auto-toggle) -ui-ux-pro-max plugin@ui-ux-pro-max-skill - -# CLI: 21st.dev component catalog + UI generation (needs `21st login`) -21st cli - -# CLI: ctx7 (doc lookup for fast-evolving libs like Next.js) -ctx7 cli -graphify cli diff --git a/lib/seo-data/seo-data.test.sh b/lib/seo-data/seo-data.test.sh index 5bbed0f..8aa6992 100644 --- a/lib/seo-data/seo-data.test.sh +++ b/lib/seo-data/seo-data.test.sh @@ -539,7 +539,7 @@ tf "gitleaks allowlist store" "$REPO/.gitleaks.toml" "seo-data/tokens" tf "gitignore venv" "$REPO/.gitignore" ".venv-seo-data" echo "── integration locks ──" -tf "skill step0 account select" "$REPO/skills/seo/SKILL.md" "COMPTE GOOGLE" +tf "skill step0 account select" "$REPO/skills/pack-seo/skills/seo/SKILL.md" "COMPTE GOOGLE" tf "analyzer calls fetch crux" "$REPO/agents/seo-analyzer.md" "fetch.sh crux" tf "analyzer calls fetch queries" "$REPO/agents/seo-analyzer.md" "fetch.sh queries" tf "analyzer gsc subsection" "$REPO/agents/seo-analyzer.md" "Performance GSC" @@ -548,10 +548,10 @@ tf "geo-analyzer wires schema_gen" "$REPO/agents/geo-analyzer.md" "fetch.sh sche tf "geo-analyzer wires content_quality" "$REPO/agents/geo-analyzer.md" "fetch.sh content_quality" echo "── account-mgmt locks ──" -tf "skill routes account verbs" "$REPO/skills/seo/SKILL.md" "forget --all" -tf "skill connect wrapper path" "$REPO/skills/seo/SKILL.md" "lib/seo-data/connect.sh" -tf "skill revocation notice" "$REPO/skills/seo/SKILL.md" "myaccount.google.com/permissions" -tf "skill label charset rule" "$REPO/skills/seo/SKILL.md" "A-Za-z0-9._-" +tf "skill routes account verbs" "$REPO/skills/pack-seo/skills/seo/SKILL.md" "forget --all" +tf "skill connect wrapper path" "$REPO/skills/pack-seo/skills/seo/SKILL.md" "lib/seo-data/connect.sh" +tf "skill revocation notice" "$REPO/skills/pack-seo/skills/seo/SKILL.md" "myaccount.google.com/permissions" +tf "skill label charset rule" "$REPO/skills/pack-seo/skills/seo/SKILL.md" "A-Za-z0-9._-" echo "── readme lock ──" tf "readme documents fetch.sh" "$REPO/lib/seo-data/README.md" "fetch.sh" diff --git a/lib/tests/doctrine-citers.test.sh b/lib/tests/doctrine-citers.test.sh index 4bacae2..0b49664 100644 --- a/lib/tests/doctrine-citers.test.sh +++ b/lib/tests/doctrine-citers.test.sh @@ -187,13 +187,13 @@ check T8h-template-rules-path "$rc1|$?" "0|1" # ── real census: the repo's own citers against CLAUDE.global.md ────────────── mapfile -t FILES < <(cd "$ROOT" && find skills agents lib rules hooks -type f \( -name '*.md' -o -name '*.sh' \) \ - -not -path 'skills/graphify/*' -not -path 'skills/impeccable/*' -not -path 'skills/synced/*' \ + -not -path 'skills/graphify/*' -not -path 'skills-external/impeccable/*' -not -path 'skills/synced/*' \ -not -path 'agents/impeccable-*' -not -path 'lib/tests/*' | sort) # T6 also scans the templates and this repo's own project rules; T3 must not # (there `CLAUDE.md` means a project CLAUDE.md, not the doctrine). mapfile -t FILES_ALL < <(cd "$ROOT" && find skills agents lib rules hooks \ templates .claude/rules -type f \( -name '*.md' -o -name '*.sh' \) \ - -not -path 'skills/graphify/*' -not -path 'skills/impeccable/*' \ + -not -path 'skills/graphify/*' -not -path 'skills-external/impeccable/*' \ -not -path 'skills/synced/*' -not -path 'agents/impeccable-*' \ -not -path 'lib/tests/*' | sort) # T8f: the T6 list reaches the two blind trees, the T3 list does not diff --git a/lib/tests/effort-routing.test.sh b/lib/tests/effort-routing.test.sh index 902865f..c4bdc22 100755 --- a/lib/tests/effort-routing.test.sh +++ b/lib/tests/effort-routing.test.sh @@ -8,6 +8,7 @@ # shellcheck disable=SC2015,SC2016 # A && ok || ko is deliberate (ok/ko never fail) set -u R="$(cd "$(dirname "$0")/../.." && pwd)" +skdir() { ls -d "$R"/skills/"$1" "$R"/skills/pack-*/skills/"$1" 2>/dev/null | head -1 | sed "s#^$R/##"; } MOD="$R/mods/model-router" RJ="$MOD/routing.json" REG="$MOD/hooks/register.ts" @@ -185,7 +186,7 @@ done # ── (e) D3 wiring markers ──────────────────────────────────────────────── mark() { # mark local ph="$1" s; shift - for s in "$@"; do has "skills/$s/SKILL.md" "route(phase=\"$ph\")"; done + for s in "$@"; do has "$(skdir "$s")/SKILL.md" "route(phase=\"$ph\")"; done } mark orchestrate feat hotfix bugfix ship-feature init-project code-clean seo geo harden web-validate audit-delta mark apply feat hotfix bugfix ship-feature init-project @@ -194,7 +195,7 @@ mark plan ship-feature init-project onboard code-clean audit-delta mark escalate ship-feature [ "$(grep -o 'route(phase="escalate")' "$R/lib/verify-secure-loop.md" | wc -l)" -eq 3 ] \ && ok || ko "verify-secure-loop.md: escalate route must appear 3 times" -for s in ship-feature init-project; do has "skills/$s/SKILL.md" 'effort="xhigh"'; done +for s in ship-feature init-project; do has "$(skdir "$s")/SKILL.md" 'effort="xhigh"'; done has "skills/tour/SKILL.md" 'effort="xhigh"' n_opus="$(grep -c 'model="opus",$' "$R/skills/onboard/SKILL.md")" n_eff="$(grep -c 'effort="xhigh",$' "$R/skills/onboard/SKILL.md")" @@ -203,7 +204,7 @@ n_eff="$(grep -c 'effort="xhigh",$' "$R/skills/onboard/SKILL.md")" bad="$(grep 'model: "fable"' "$R/agents/client-handover-writer.md" | grep -vc 'effort="high"')" [ "$bad" -eq 0 ] && ok || ko "client-handover-writer: $bad model: \"fable\" line(s) without effort=\"high\"" for s in ship-feature init-project feat bugfix web-validate seo hotfix geo harden code-clean audit-delta tour onboard; do - has "skills/$s/SKILL.md" 'ROUTING: follow $HOME/.claude/lib/effort-shift.md' + has "$(skdir "$s")/SKILL.md" 'ROUTING: follow $HOME/.claude/lib/effort-shift.md' done has "agents/client-handover-writer.md" 'ROUTING: follow $HOME/.claude/lib/effort-shift.md' diff --git a/lib/tests/fixtures/pack-census-old-citers.sh b/lib/tests/fixtures/pack-census-old-citers.sh new file mode 100644 index 0000000..84935e4 --- /dev/null +++ b/lib/tests/fixtures/pack-census-old-citers.sh @@ -0,0 +1 @@ +ls $HOME/.claude/skills/a2 skills-disabled/foo; bash lib/toggle-external.sh; cat .active-profile; lib/profiles/web.profile diff --git a/lib/tests/gstack-removed.test.sh b/lib/tests/gstack-removed.test.sh deleted file mode 100755 index 91ced07..0000000 --- a/lib/tests/gstack-removed.test.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env bash -# lib/tests/gstack-removed.test.sh — GSTACK_REMOVED denylist honored by -# every "bring gstack back" path: profile.sh `gstack on` and -# toggle-external.sh `enable gstack` both skip a policy-removed name and -# leave it parked, restoring only what policy allows; gstack_is_removed() -# itself, positive + negative. Covers contract criterion 17. Hermetic: -# fixture repo via PROFILE_REPO_OVERRIDE / TOGGLE_EXTERNAL_REPO_OVERRIDE — -# same harness as lib/tests/profile-default.test.sh and -# lib/tests/toggle-external-repo-resolution.test.sh. -set -u -ROOT="$(cd "$(dirname "$0")/../.." && pwd)" -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; } -check_has() { case "$2" in *"$3"*) pass=$((pass+1));; *) fail=$((fail+1)); - printf 'FAIL %s: [%s] does not contain [%s]\n' "$1" "$2" "$3";; esac; } -check_not() { case "$2" in *"$3"*) fail=$((fail+1)); - printf 'FAIL %s: [%s] unexpectedly contains [%s]\n' "$1" "$2" "$3";; *) pass=$((pass+1));; esac; } - -# mk_fixture — minimal repo: profile.sh + toggle-external.sh + -# gstack-removed.sh under lib/, one removed name (ship) and one kept name -# (browse) parked in skills-disabled/. -mk_fixture() { - local fx="$1" - mkdir -p "$fx/skills" "$fx/skills-disabled/gstack__ship" \ - "$fx/skills-disabled/gstack__browse" "$fx/lib" - cp "$ROOT/lib/profile.sh" "$ROOT/lib/toggle-external.sh" \ - "$ROOT/lib/gstack-removed.sh" "$fx/lib/" -} - -# --- T1-T5: profile.sh gstack on restores browse, skips + parks ship --- -FX1="$(mktemp -d)"; mk_fixture "$FX1" -out="$(PROFILE_REPO_OVERRIDE="$FX1" bash "$FX1/lib/profile.sh" gstack on 2>&1)" -check T1-browse-restored "$([ -e "$FX1/skills/browse" ] && echo on || echo off)" on -check T2-ship-parked "$([ -e "$FX1/skills-disabled/gstack__ship" ] && echo p || echo n)" p -check T3-ship-not-live "$([ -e "$FX1/skills/ship" ] && echo on || echo off)" off -check_has T4-skip-names-ship "$out" "ship" -check_has T5-real-count "$out" "1 parked gstack skills restored" -rm -rf "$FX1" - -# --- T6-T9: toggle-external.sh enable gstack — same skip + restore --- -FX2="$(mktemp -d)"; mk_fixture "$FX2" -out="$(TOGGLE_EXTERNAL_REPO_OVERRIDE="$FX2" bash "$FX2/lib/toggle-external.sh" enable gstack 2>&1)" -check T6-browse-restored "$([ -e "$FX2/skills/browse" ] && echo on || echo off)" on -check T7-ship-parked "$([ -e "$FX2/skills-disabled/gstack__ship" ] && echo p || echo n)" p -check T8-ship-not-live "$([ -e "$FX2/skills/ship" ] && echo on || echo off)" off -check_has T9-skip-names-ship "$out" "ship" -rm -rf "$FX2" - -# --- T10-T11: toggle-external.sh, only removed names parked — 0 restored, -# the policy message fires instead of the "re-run gstack setup" hint --- -FX3="$(mktemp -d)" -mkdir -p "$FX3/skills" "$FX3/skills-disabled/gstack__ship" "$FX3/lib" -cp "$ROOT/lib/toggle-external.sh" "$ROOT/lib/gstack-removed.sh" "$FX3/lib/" -out="$(TOGGLE_EXTERNAL_REPO_OVERRIDE="$FX3" bash "$FX3/lib/toggle-external.sh" enable gstack 2>&1)" -check_has T10-policy-msg "$out" "policy-removed skills remain parked" -check_not T11-no-setup-hint "$out" "re-run gstack setup" -rm -rf "$FX3" - -# --- T12-T13: gstack_is_removed() itself, positive + negative --- -# shellcheck source=lib/gstack-removed.sh disable=SC1091 -source "$ROOT/lib/gstack-removed.sh" -gstack_is_removed ship; check T12-removed-positive "$?" 0 -gstack_is_removed browse; check T13-removed-negative "$?" 1 - -printf 'PASS=%s FAIL=%s\n' "$pass" "$fail"; [ "$fail" -eq 0 ] diff --git a/lib/tests/higgsfield.test.sh b/lib/tests/higgsfield.test.sh index 689218b..c3110ae 100644 --- a/lib/tests/higgsfield.test.sh +++ b/lib/tests/higgsfield.test.sh @@ -2,9 +2,7 @@ # lib/tests/higgsfield.test.sh — hermetic suite for the Higgsfield pack. # sync lib/higgsfield-skills.sh against a local git repo shaped like # upstream (no network), and its CLI probes against a fake CLI -# toggle lib/toggle-external.sh `higgsfield` / `higgsfield-websites` -# against a fixture tree, fake CLIs first on PATH -# wiring static locks on the installers (order, off by default) +# wiring static locks on the installers (order) # Each named case prints one `PASS ` or `FAIL :
` line. set -u ROOT="$(cd "$(dirname "$0")/../.." && pwd)" @@ -111,7 +109,7 @@ probe() { # ── sync ──────────────────────────────────────────────────── UP="$WORK/upstream"; mk_upstream "$UP" # The repo path carries a space on purpose: every expansion must be quoted. -R1="$WORK/r 1"; mkdir -p "$R1/skills" "$R1/skills-disabled" +R1="$WORK/r 1"; mkdir -p "$R1/skills" EXT="$R1/skills-external" expect fixture "$(yn test -f "$UP/.git/HEAD")" yes @@ -137,16 +135,6 @@ expect stale-out "$(yn test -e "$EXT/higgsfield-generate/old.md")" no expect new-in "$(yn test -f "$EXT/higgsfield-generate/new.md")" yes verdict SYNC_REFRESH_DROPS_STALE -ln -s "$EXT/higgsfield-soul-id" "$R1/skills-disabled/higgsfield-soul-id" -ln -s "$EXT/higgsfield-generate" "$R1/skills/higgsfield-generate" -expect rc-count "$(sync_into "$R1")" "0:3" -expect parked-link "$(yn test -L "$R1/skills-disabled/higgsfield-soul-id")" yes -expect parked-reads \ - "$(yn test -f "$R1/skills-disabled/higgsfield-soul-id/SKILL.md")" yes -expect not-enabled "$(yn test -e "$R1/skills/higgsfield-soul-id")" no -expect live-reads "$(yn test -f "$R1/skills/higgsfield-generate/SKILL.md")" yes -verdict SYNC_KEEPS_PARKED - BARE="$WORK/bare-upstream"; mkdir -p "$BARE"; echo "x" > "$BARE/README.md" git_q "$BARE" init; git_q "$BARE" add -A; git_q "$BARE" commit -m fixture expect no-repo "$(sync_into "$R1" "$WORK/no-such-repo")" "1:0" @@ -171,158 +159,10 @@ chmod +x "$GT/gtimeout" expect gtimeout "$(probe "$BIN:$GT:$CLEAN" higgsfield_signed_in)" "rc=0" verdict PROBES_SILENT -# ── toggle ────────────────────────────────────────────────── -# mk_toggle_fx [skill...] — fixture repo: the toggle script plus one -# skills-external source per named skill (none → installed-nothing tree). -mk_toggle_fx() { - local fx="$1" s; shift - mkdir -p "$fx/lib" "$fx/skills" - cp "$ROOT/lib/toggle-external.sh" "$ROOT/lib/gstack-removed.sh" "$fx/lib/" - for s in "$@"; do - mkdir -p "$fx/skills-external/$s" - echo "---" > "$fx/skills-external/$s/SKILL.md" - done -} -PACK=(higgsfield-generate higgsfield-soul-id higgsfield-websites) - -# tog — run the fixture's toggle script, fake CLIs first. -tog() { - local fx="$1"; shift - TOGGLE_EXTERNAL_REPO_OVERRIDE="$fx" PATH="$BIN:$PATH" \ - bash "$fx/lib/toggle-external.sh" "$@" 2>&1 -} -# list_row — the status column of `list` for one tool. -list_row() { tog "$1" list | awk -v t="$2" '$1 == t { print $2 }'; } - -F0="$WORK/f0"; mk_toggle_fx "$F0" -F1="$WORK/f1"; mk_toggle_fx "$F1" "${PACK[@]}" -expect pack-missing "$(tog "$F0" status higgsfield)" missing -expect web-missing "$(tog "$F0" status higgsfield-websites)" missing -expect pack-disabled "$(tog "$F1" status higgsfield)" disabled -expect web-disabled "$(tog "$F1" status higgsfield-websites)" disabled -ln -s "$F1/skills-external/higgsfield-generate" "$F1/skills/higgsfield-generate" -expect pack-partial "$(tog "$F1" status higgsfield)" enabled -expect web-apart "$(tog "$F1" status higgsfield-websites)" disabled -expect list-pack "$(list_row "$F1" higgsfield)" enabled -expect list-web "$(list_row "$F1" higgsfield-websites)" disabled -verdict STATUS_STATES - -F2="$WORK/f2"; mk_toggle_fx "$F2" "${PACK[@]}" -out="$(tog "$F2" enable higgsfield)"; rc=$? -expect rc "$rc" 0 -expect generate "$(readlink "$F2/skills/higgsfield-generate")" \ - "$F2/skills-external/higgsfield-generate" -expect soul-id "$(readlink "$F2/skills/higgsfield-soul-id")" \ - "$F2/skills-external/higgsfield-soul-id" -expect no-websites "$(yn test -e "$F2/skills/higgsfield-websites")" no -expect_has count "$out" "higgsfield enabled (2 skills: 0 restored, 2 linked)" -out="$(tog "$F2" enable higgsfield)"; rc=$? -expect again-rc "$rc" 0 -expect_has again "$out" "higgsfield already enabled" -verdict ENABLE_PACK_EXCLUDES_WEBSITES - -# The media pack is an allowlist: a synced skill nobody listed is reported, -# never linked; neither is a listed name whose directory holds no SKILL.md. -F8="$WORK/f 8"; mk_toggle_fx "$F8" "${PACK[@]}" higgsfield-newcomer -mkdir -p "$F8/skills-external/higgsfield-brandkit" \ - "$F8/skills-external/higgsfield-noskill" -out="$(tog "$F8" enable higgsfield)"; rc=$? -expect rc "$rc" 0 -expect_has count "$out" "higgsfield enabled (2 skills: 0 restored, 2 linked)" -expect newcomer-off "$(yn test -e "$F8/skills/higgsfield-newcomer")" no -expect brandkit-off "$(yn test -e "$F8/skills/higgsfield-brandkit")" no -expect_has reported "$out" "higgsfield-newcomer" -expect_not noskill-quiet "$out" "higgsfield-noskill" -expect links "$(entries "$F8/skills")" 2 -# Enabled is the steady state: a re-run must still name the drift. -out="$(tog "$F8" enable higgsfield)"; rc=$? -expect again-rc "$rc" 0 -expect_has again-state "$out" "higgsfield already enabled" -expect_has again-reported "$out" "higgsfield-newcomer" -verdict UNLISTED_NOT_LINKED - -F3="$WORK/f3"; mk_toggle_fx "$F3" "${PACK[@]}" -out="$(tog "$F3" enable higgsfield-websites)"; rc=$? -expect rc "$rc" 0 -expect link "$(readlink "$F3/skills/higgsfield-websites")" \ - "$F3/skills-external/higgsfield-websites" -expect no-generate "$(yn test -e "$F3/skills/higgsfield-generate")" no -expect pack-status "$(tog "$F3" status higgsfield)" disabled -expect web-status "$(tog "$F3" status higgsfield-websites)" enabled -tog "$F3" disable higgsfield-websites >/dev/null -out="$(FAKE_HF_SESSION=out tog "$F3" enable higgsfield-websites)"; rc=$? -expect hint-rc "$rc" 0 -expect_has web-hint "$out" "higgsfield auth login" -verdict ENABLE_WEBSITES_ALONE - -# Continues on F2: the pack is enabled, websites is not. -tog "$F2" enable higgsfield-websites >/dev/null -out="$(tog "$F2" disable higgsfield)"; rc=$? -expect rc "$rc" 0 -expect_has msg "$out" "higgsfield disabled (2 skills parked)" -expect parked "$(yn test -L "$F2/skills-disabled/higgsfield-generate")" yes -expect unlinked "$(yn test -e "$F2/skills/higgsfield-generate")" no -expect web-untouched "$(yn test -e "$F2/skills/higgsfield-websites")" yes -out="$(tog "$F2" enable higgsfield)" -expect_has restored "$out" "2 restored, 0 linked" -tog "$F2" disable higgsfield-websites >/dev/null -expect web-parked "$(yn test -L "$F2/skills-disabled/higgsfield-websites")" yes -expect pack-on "$(tog "$F2" status higgsfield)" enabled -verdict DISABLE_PARKS - -F4="$WORK/f4"; mk_toggle_fx "$F4" "${PACK[@]}" -out="$(FAKE_HF_SESSION=out tog "$F4" enable higgsfield)"; rc=$? -expect out-rc "$rc" 0 -expect out-linked "$(yn test -e "$F4/skills/higgsfield-generate")" yes -expect_has out-hint "$out" "higgsfield auth login" -F5="$WORK/f5"; mk_toggle_fx "$F5" "${PACK[@]}" -out="$(FAKE_HF_SESSION=in tog "$F5" enable higgsfield)" -expect_not in-quiet "$out" "auth login" -expect_not in-no-token "$out" "fixture-token" -F6="$WORK/f6"; mk_toggle_fx "$F6" "${PACK[@]}" -out="$(TOGGLE_EXTERNAL_REPO_OVERRIDE="$F6" PATH="$CLEAN" \ - bash "$F6/lib/toggle-external.sh" enable higgsfield 2>&1)"; rc=$? -expect absent-rc "$rc" 0 -expect absent-linked "$(yn test -e "$F6/skills/higgsfield-generate")" yes -expect_has absent-hint "$out" "not on PATH" -F9="$WORK/f9"; mk_toggle_fx "$F9" "${PACK[@]}" -out="$(FAKE_HF_BINARY=missing tog "$F9" enable higgsfield)"; rc=$? -expect shim-rc "$rc" 0 -expect_has shim-hint "$out" "does not answer" -expect_not shim-not-login "$out" "auth login" -verdict SIGNED_OUT_WARNS - -out="$(tog "$F0" enable higgsfield)"; rc=$? -expect pack-rc "$rc" 1 -expect_has pack-path "$out" "$F0/skills-external" -out="$(tog "$F0" enable higgsfield-websites)"; rc=$? -expect web-rc "$rc" 1 -expect_has web-path "$out" "$F0/skills-external/higgsfield-websites" -verdict ENABLE_MISSING_ERRS - -# The pack arms are shared with 21st: its behaviour must not move. -F7="$WORK/f7"; mk_toggle_fx "$F7" 21st-one 21st-two -expect off "$(tog "$F7" status 21st)" disabled -out="$(tog "$F7" enable 21st)" -expect_has on "$out" "21st enabled (2 skills: 0 restored, 2 linked)" -expect_not quiet "$out" "21st login" -expect hf-apart "$(tog "$F7" status higgsfield)" missing -out="$(tog "$F7" disable 21st)" -expect_has parked "$out" "21st disabled (2 skills parked)" -verdict PACK_21ST_UNCHANGED - # ── wiring ────────────────────────────────────────────────── # count — matching lines (0 when none). count() { grep -cF -- "$2" "$ROOT/$1"; } -# Positive control first: the pattern does bite on a line that carries it. -expect control "$(echo 'higgsfield-x external' | grep -cF higgsfield)" 1 -expect link-sh "$(count link.sh higgsfield)" 0 -expect profile-sh "$(count lib/profile.sh higgsfield)" 0 -expect profiles \ - "$(cat "$ROOT"/lib/profiles/*.profile | grep -cF higgsfield)" 0 -verdict OFF_BY_DEFAULT_WIRING - # ln_first / ln_last — line number of a match. ln_first() { grep -nF -- "$2" "$ROOT/$1" | head -1 | cut -d: -f1; } ln_last() { grep -nF -- "$2" "$ROOT/$1" | tail -1 | cut -d: -f1; } diff --git a/lib/tests/model-routing.test.sh b/lib/tests/model-routing.test.sh index ed47650..5aabff4 100755 --- a/lib/tests/model-routing.test.sh +++ b/lib/tests/model-routing.test.sh @@ -2,6 +2,7 @@ # lib/tests/model-routing.test.sh — census: gate wiring + pins + executor shape (BDR-066, BDR-076) set -u R="$(cd "$(dirname "$0")/../.." && pwd)" +skdir() { ls -d "$R"/skills/"$1" "$R"/skills/pack-*/skills/"$1" 2>/dev/null | head -1 | sed "s#^$R/##"; } pass=0; fail=0 ok() { pass=$((pass+1)); } ko() { fail=$((fail+1)); printf 'FAIL %s\n' "$1"; } @@ -11,11 +12,11 @@ fm_lacks() { if awk 'NR<=10' "$R/$1" | grep -qF "$2"; then ko "$1 frontmatter mu # 1) gate wired in the 17 reflection skills (orchestrators, /analyze, /guardrails, /a11y) for s in ship-feature init-project feat bugfix onboard seo geo web-validate harden audit-delta tour code-clean hotfix client-handover analyze guardrails a11y; do - has "skills/$s/SKILL.md" 'lib/model-gate.md' + has "$(skdir "$s")/SKILL.md" 'lib/model-gate.md' done # 2) gate NOT wired in the pure-execution/read-only skills (exclusion list) for s in commit-change doc status release-candidate refactor; do - lacks "skills/$s/SKILL.md" 'lib/model-gate.md' + lacks "$(skdir "$s")/SKILL.md" 'lib/model-gate.md' done # 3) executor + gate pins has "agents/feater.md" 'model: sonnet' @@ -31,7 +32,7 @@ lacks "agents/feater.md" 'AskUserQuestion' has "skills/ship-feature/SKILL.md" 'model: "sonnet"' has "skills/init-project/SKILL.md" 'model: "sonnet"' # 6) web-validate applies via L1 applier -has "skills/web-validate/SKILL.md" 'subagent_type="hotfixer"' +has "skills/pack-web-validate/skills/web-validate/SKILL.md" 'subagent_type="hotfixer"' # 7) wave-2 — pure-execution skills dispatch their agent (pin takes effect, off the big session model) has "skills/doc/SKILL.md" 'subagent_type="doc-syncer"' has "skills/status/SKILL.md" 'subagent_type="status-reporter"' @@ -105,9 +106,9 @@ lacks "agents/plugin-advisor.md" 'PHASE 1 — DETECT' has "lib/plugin-gate.md" 'subagent_type="plugin-probe"' has "lib/plugin-gate.md" 'subagent_type="plugin-advisor"' for s in plugin-check onboard init-project ship-feature; do - has "skills/$s/SKILL.md" 'lib/plugin-gate.md' + has "$(skdir "$s")/SKILL.md" 'lib/plugin-gate.md' # shellcheck disable=SC2016 # literal $HOME wanted: matching the exact inline-load string - lacks "skills/$s/SKILL.md" 'Load `$HOME/.claude/agents/plugin-advisor.md`' + lacks "$(skdir "$s")/SKILL.md" 'Load `$HOME/.claude/agents/plugin-advisor.md`' done # 14) BDR-077 W2/S2 — doc pipeline: ONE agent, TWO modes around the # dispatcher's gate (audit = opus via call-site override — documented @@ -124,10 +125,10 @@ has "skills/doc/SKILL.md" 'model="opus"' has "skills/doc/SKILL.md" 'MODE: patch' lacks "agents/scaffolder.md" 'INLINE-LOAD' for s in bugfix hotfix feat ship-feature init-project; do - has "skills/$s/SKILL.md" 'MODE: audit' - has "skills/$s/SKILL.md" 'doc-syncer", model="opus"' + has "$(skdir "$s")/SKILL.md" 'MODE: audit' + has "$(skdir "$s")/SKILL.md" 'doc-syncer", model="opus"' # shellcheck disable=SC2016 # literal $HOME wanted: matching the exact inline-load string - lacks "skills/$s/SKILL.md" 'Load `$HOME/.claude/agents/doc-syncer.md`' + lacks "$(skdir "$s")/SKILL.md" 'Load `$HOME/.claude/agents/doc-syncer.md`' done # 15) BDR-077 W2 — last inline execution converted: scaffolder + onboarder # are DISPATCHED (pins live); their gates/arbitration stay in the @@ -166,14 +167,14 @@ has "agents/geo-analyzer.md" 'MODE: collect' has "agents/geo-analyzer.md" 'MODE: judge' has "agents/geo-analyzer.md" 'MODE: template' has "agents/geo-analyzer.md" 'COLLECTION COMPLETE' -has "skills/seo/SKILL.md" 'MODE: collect' -has "skills/seo/SKILL.md" 'seo-analyzer", model="sonnet"' -has "skills/seo/SKILL.md" 'never re-derive a score' -has "skills/seo/SKILL.md" 'DISPATCHER ERROR CONTRACT' -has "skills/geo/SKILL.md" 'MODE: collect' -has "skills/geo/SKILL.md" 'geo-analyzer", model="sonnet"' -has "skills/geo/SKILL.md" 'ERROR CONTRACT' -has "skills/geo/SKILL.md" 'never re-derive a score' +has "skills/pack-seo/skills/seo/SKILL.md" 'MODE: collect' +has "skills/pack-seo/skills/seo/SKILL.md" 'seo-analyzer", model="sonnet"' +has "skills/pack-seo/skills/seo/SKILL.md" 'never re-derive a score' +has "skills/pack-seo/skills/seo/SKILL.md" 'DISPATCHER ERROR CONTRACT' +has "skills/pack-seo/skills/geo/SKILL.md" 'MODE: collect' +has "skills/pack-seo/skills/geo/SKILL.md" 'geo-analyzer", model="sonnet"' +has "skills/pack-seo/skills/geo/SKILL.md" 'ERROR CONTRACT' +has "skills/pack-seo/skills/geo/SKILL.md" 'never re-derive a score' has "agents/handover-doc-writer.md" 'SYNTH REPORT' printf 'model-routing census: %d pass, %d fail\n' "$pass" "$fail" diff --git a/lib/tests/pack-census.test.sh b/lib/tests/pack-census.test.sh new file mode 100755 index 0000000..b74668b --- /dev/null +++ b/lib/tests/pack-census.test.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash +# lib/tests/pack-census.test.sh — lib/pack-census.sh: pack layout (manifest +# name = folder, entries resolve, no skill twice, retired gstack names absent), +# fragment invariants (same key set, fixed values, deny set, full = manifest +# defaults), old-layout citers. Fixture cases, then the hermetic part of the +# census on the real repo (dangling targets are WARN without --installed). +set -u +unset CLAUDE_PROFILE CLAUDE_PROFILE_SETTINGS +ROOT="$(cd "$(dirname "$0")/../.." && pwd)" +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; } +check_has() { case "$2" in *"$3"*) pass=$((pass+1));; *) fail=$((fail+1)); + printf 'FAIL %s: [%s] does not contain [%s]\n' "$1" "$2" "$3";; esac; } + +FX="$(mktemp -d)"; trap 'rm -rf "$FX"' EXIT +mkdir -p "$FX/lib/profiles" "$FX/hooks" "$FX/skills/core-a"; touch "$FX/skills/core-a/SKILL.md" +printf 'gs-dead\n' > "$FX/lib/gstack-removed.list" +mk_pack() { # name defaultEnabled skill... + local n="$1" d="$2"; shift 2 + mkdir -p "$FX/skills/pack-$n/.claude-plugin" "$FX/skills/pack-$n/skills" + printf '{"name":"pack-%s","version":"1.0.0","defaultEnabled":%s}\n' "$n" "$d" \ + > "$FX/skills/pack-$n/.claude-plugin/plugin.json" + for s in "$@"; do mkdir -p "$FX/skills-external/$s"; touch "$FX/skills-external/$s/SKILL.md" + ln -s "../../../skills-external/$s" "$FX/skills/pack-$n/skills/$s"; done +} +mk_pack alpha true a1 a2 +mk_pack beta false b1 +frag() { # name alpha beta deny(yes|no) — the two real connector names + local d=""; [ "$4" = yes ] && d=', "deniedMcpServers": [{"serverName": "claude.ai higgsfield"}, {"serverName": "claude.ai Higgsfield AI"}]' + printf '{"enabledPlugins": {"model-router@skills-dir": true, "pack-alpha@skills-dir": %s, "pack-beta@skills-dir": %s, "security-guidance@claude-code-plugins": true, "example-skills@anthropic-agent-skills": false, "brightdata-plugin@synced": false}%s}\n' \ + "$2" "$3" "$d" > "$FX/lib/profiles/$1.json"; } +frag full true false no; frag dev false false yes +census() { bash "$ROOT/lib/pack-census.sh" --repo "$FX" "$@" 2>&1; } + +out="$(census)"; rc=$? +check T1-green-rc "$rc" 0; check_has T1-green "$out" "PACKS OK 2 packs 3 skills" + +rm -r "$FX/skills-external/b1" +out="$(census)"; rc=$? +check T2-off-dangling-rc "$rc" 0; check_has T2-off-dangling "$out" "WARN pack-beta: b1 target missing" +rm -r "$FX/skills-external/a2" +out="$(census)"; rc=$? +check T3-on-dangling-test-rc "$rc" 0; check_has T3-on-dangling-test "$out" "WARN pack-alpha: a2 target missing" +out="$(census --installed)"; rc=$? +check T3-on-dangling-doctor-rc "$rc" 1; check_has T3-on-dangling-doctor "$out" "RED pack-alpha: a2 target missing (pack ON)" +mkdir -p "$FX/skills-external/a2" "$FX/skills-external/b1"; touch "$FX/skills-external/a2/SKILL.md" "$FX/skills-external/b1/SKILL.md" + +sed -i.bak 's/"pack-alpha"/"pack-alpho"/' "$FX/skills/pack-alpha/.claude-plugin/plugin.json" +out="$(census)"; rc=$? +check T4-name-rc "$rc" 1; check_has T4-name "$out" "RED pack-alpha: manifest name is pack-alpho" +mv "$FX/skills/pack-alpha/.claude-plugin/plugin.json.bak" "$FX/skills/pack-alpha/.claude-plugin/plugin.json" + +ln -s ../skills-external/a1 "$FX/skills/a1" +out="$(census)"; rc=$? +check T5-dup-rc "$rc" 1; check_has T5-dup "$out" "RED a1 listed twice: skills/a1 and pack-alpha — rm skills/a1 (a flat link)" +rm "$FX/skills/a1" + +ln -s "../../../skills-external/a1" "$FX/skills/pack-alpha/skills/gs-dead" +out="$(census)"; rc=$? +check T6-retired-rc "$rc" 1; check_has T6-retired "$out" "RED pack-alpha: gs-dead is a retired gstack skill" +rm "$FX/skills/pack-alpha/skills/gs-dead" +mv "$FX/lib/gstack-removed.list" "$FX/lib/gstack-removed.list.off" +out="$(census)"; rc=$? +check T6-nolist-rc "$rc" 1; check_has T6-nolist "$out" "RED lib/gstack-removed.list missing" +mv "$FX/lib/gstack-removed.list.off" "$FX/lib/gstack-removed.list" + +printf 'Read ~/.claude/skills/a1/SKILL.md\n' > "$FX/hooks/x.sh" +cp "$ROOT/lib/tests/fixtures/pack-census-old-citers.sh" "$FX/hooks/y.sh" # the old-layout terms live in a fixture, not in this file (the census scans lib/tests/) +out="$(census)"; rc=$? +check T7-citer-rc "$rc" 1 +check_has T7-citer-tilde "$out" "RED hooks/x.sh cites ~/.claude/skills/a1" +check_has T7-citer-home "$out" "RED hooks/y.sh cites \$HOME/.claude/skills/a2" +check_has T7-citer-disabled "$out" "RED hooks/y.sh cites skills-disable""d/" +check_has T7-citer-toggle "$out" "RED hooks/y.sh cites toggle-externa""l" +check_has T7-citer-active "$out" "RED hooks/y.sh cites .active-profil""e" +check_has T7-citer-profile "$out" "RED hooks/y.sh cites lib/profiles/web.profil""e" +rm "$FX/hooks/x.sh" "$FX/hooks/y.sh" + +# fragment invariants +printf '{"enabledPlugins": {"model-router@skills-dir": true, "pack-alpha@skills-dir": true}}\n' > "$FX/lib/profiles/short.json" +out="$(census)"; rc=$? +check T8-keyset-rc "$rc" 1; check_has T8-keyset "$out" "RED lib/profiles/short.json: key set differs from full.json" +rm "$FX/lib/profiles/short.json" +frag full true true no +out="$(census)"; rc=$? +check T9-full-defaults-rc "$rc" 1; check_has T9-full-defaults "$out" "RED lib/profiles/full.json: pack-beta@skills-dir is true but the manifest default is false" +frag full true false no +sed -i.bak 's/"security-guidance@claude-code-plugins": true/"security-guidance@claude-code-plugins": false/' "$FX/lib/profiles/dev.json" +out="$(census)"; rc=$? +check T10-fixed-rc "$rc" 1; check_has T10-fixed "$out" "RED lib/profiles/dev.json: security-guidance@claude-code-plugins must be true" +mv "$FX/lib/profiles/dev.json.bak" "$FX/lib/profiles/dev.json" + +# real repo, hermetic part +out="$(bash "$ROOT/lib/pack-census.sh" 2>&1)"; rc=$? +check T11-real-rc "$rc" 0; check_has T11-real "$out" "PACKS OK 9 packs 55 skills" +check T12-shellcheck "$(shellcheck "$ROOT/lib/pack-census.sh" >/dev/null 2>&1 && echo ok)" ok +check T12-width "$(LC_ALL=C awk 'length($0) > 80' "$ROOT/lib/pack-census.sh" | wc -l | tr -d ' ')" 0 +printf 'PASS=%s FAIL=%s\n' "$pass" "$fail"; [ "$fail" -eq 0 ] diff --git a/lib/tests/plan-challenger.test.sh b/lib/tests/plan-challenger.test.sh index 9733f4f..94f0743 100644 --- a/lib/tests/plan-challenger.test.sh +++ b/lib/tests/plan-challenger.test.sh @@ -5,6 +5,7 @@ # adversarial behavior needs a live model (manual smoke), not a CI gate. set -u R="$(cd "$(dirname "$0")/../.." && pwd)" +skdir() { ls -d "$R"/skills/"$1" "$R"/skills/pack-*/skills/"$1" 2>/dev/null | head -1 | sed "s#^$R/##"; } pass=0; fail=0 ok() { pass=$((pass+1)); } ko() { fail=$((fail+1)); printf 'FAIL %s\n' "$1"; } @@ -41,8 +42,8 @@ has "$L" "fix-bundle" # 3) every reflection orchestrator wires the phase + carries a challenge summary # (hotfix wires it under a logic-only guard — STEP 1.8) for s in ship-feature init-project feat bugfix hotfix onboard audit-delta code-clean seo geo harden web-validate; do - has "skills/$s/SKILL.md" "lib/challenge-plan.md" - has "skills/$s/SKILL.md" "CHALLENGE SUMMARY" + has "$(skdir "$s")/SKILL.md" "lib/challenge-plan.md" + has "$(skdir "$s")/SKILL.md" "CHALLENGE SUMMARY" done printf 'plan-challenge structure lock: %d pass, %d fail\n' "$pass" "$fail" diff --git a/lib/tests/profile-census.test.sh b/lib/tests/profile-census.test.sh deleted file mode 100755 index 8d150d0..0000000 --- a/lib/tests/profile-census.test.sh +++ /dev/null @@ -1,193 +0,0 @@ -#!/usr/bin/env bash -# lib/tests/profile-census.test.sh — profile catalog invariants (skill- -# catalog prune, 2026-09-28): no GSTACK_REMOVED name listed in any -# profile, exactly one profile carries the `# SUPERSET-OF: full` marker -# and it is a superset of full + the parked tools + every name any -# profile carries, and `full` carries every name any other (non-max) -# profile carries save one named exception (pr-review-toolkit). -# -# Hermetic: a passing baseline fixture, then one single-change mutant per -# invariant (each mutant is a positive control — it MUST be detected). -# Live part runs against this repo's real lib/profiles/ (a violation -# there fails the suite for real, same style as -# lib/tests/skill-routing-census.test.sh). -set -u -ROOT="$(cd "$(dirname "$0")/../.." && pwd)" -# shellcheck source=lib/gstack-removed.sh disable=SC1091 -source "$ROOT/lib/gstack-removed.sh" - -# Parked = kept installed, out of `full`, listed only in the superset -# profile (`max`). Names come from the single denylist above for REMOVED; -# PARKED has no such shared source (it is a positive allowlist, not a -# denylist), so it is spelled out here. -PARKED=(make-pdf diagram 21st-ai 21st-ui-explore 21st-ui-review) - -# full carries every name any other (non-max) profile carries, with one -# named exception: pr-review-toolkit is deliberately out of full (audit -# 2026-07-02 #12, heaviest single plugin, ~2.2k tokens/session, PR-only -# use) — measured 2026-09-28: it is the only name any specialized -# profile carries that full lacks (audit.profile). -FULL_EXCEPTIONS=(pr-review-toolkit) - -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; } - -# census_check [parked_csv] [exceptions_csv] — one -# violation code per line on stdout, rc 0 iff none. REMOVED always comes -# from the sourced denylist (single source, never overridden); -# PARKED/FULL_EXCEPTIONS default to the real production sets and can be -# overridden per call (fixture runs use a small standalone catalog). -census_check() { - local dir="$1" - # Unset (arg omitted, live call) falls back to the real production - # set; an explicitly EMPTY string (fixture calls) means "none" and - # must stay empty — hence "-" defaults, never ":-" (which would treat - # empty the same as unset and silently pull the real set back in). - local parked_csv="${2-$(IFS=,; echo "${PARKED[*]}")}" - local exc_csv="${3-$(IFS=,; echo "${FULL_EXCEPTIONS[*]}")}" - local removed_csv out - removed_csv="$(IFS=,; echo "${GSTACK_REMOVED[*]}")" - out=$(python3 - "$dir" "$removed_csv" "$parked_csv" "$exc_csv" <<'PY' -import glob, os, re, sys - -def entries(path): - """Entry = first whitespace token of a non-blank, non-comment line.""" - names = set() - for line in open(path, encoding="utf-8"): - s = line.strip() - if s and not s.startswith("#"): - names.add(s.split()[0]) - return names - -def has_marker(path): - text = open(path, encoding="utf-8").read() - return re.search(r'^# SUPERSET-OF: full\s*$', text, re.M) is not None - -def check_removed(by_name, removed): - return [f"REMOVED_LISTED:{n}:{e}" for n, ents in by_name.items() - for e in sorted(ents & removed)] - -def find_superset(files): - hits = [p for p in files if has_marker(p)] - if not hits: - return None, ["NO_SUPERSET"] - if len(hits) > 1: - return None, ["MANY_SUPERSETS"] - return os.path.basename(hits[0])[:-len(".profile")], [] - -def check_superset_gap(by_name, sname, parked, exceptions): - full = by_name.get("full", set()) - target = full | parked | exceptions - return [f"SUPERSET_GAP:{n}" for n in sorted(target - by_name[sname])] - -def check_max_gap(by_name, sname, removed): - union = set().union(*by_name.values()) - gap = (union - removed) - by_name[sname] - return [f"MAX_GAP:{n}" for n in sorted(gap)] - -def check_full_gap(by_name, sname, removed, exceptions): - trio = {"21st-ai", "21st-ui-explore", "21st-ui-review"} - src = set().union(*(e for n, e in by_name.items() - if n not in ("full", sname))) - full = by_name.get("full", set()) - gap = src - full - removed - trio - exceptions - return [f"FULL_GAP:{n}" for n in sorted(gap)] - -def main(): - d, removed_csv, parked_csv, exc_csv = sys.argv[1:5] - removed = {x for x in removed_csv.split(",") if x} - parked = {x for x in parked_csv.split(",") if x} - exceptions = {x for x in exc_csv.split(",") if x} - - files = sorted(glob.glob(os.path.join(d, "*.profile"))) - by_name = {os.path.basename(p)[:-len(".profile")]: entries(p) - for p in files} - - violations = check_removed(by_name, removed) - sname, sup_violations = find_superset(files) - violations += sup_violations - if sname: - violations += check_superset_gap(by_name, sname, parked, exceptions) - violations += check_max_gap(by_name, sname, removed) - violations += check_full_gap(by_name, sname, removed, exceptions) - - # Reason codes only, one per line; no exit here — the bash caller - # derives pass/fail from whether this captured output is empty. - print("\n".join(violations)) - -main() -PY -) - if [ -n "$out" ]; then - printf '%s\n' "$out" - return 1 - fi - return 0 -} - -# run_mutant