feat(hooks,doctor): statusline and banner read profile.sh current --plain once; doctor runs the pack census and checks cc.sh sourcing, user-scope residue and the opus default

This commit is contained in:
bchanot committed 2026-11-02 01:34:50 +01:00
1 parent 58958229d9
commit 6509ab2958
10 files changed
+131 -202

No files matched your search

+6 -5
View File
@@ -26,11 +26,12 @@ detect_superpowers() {
# --- Toggle plugins ---
detect_gstack() {
# 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/pack-gstack-browser/skills/browse" ] \
|| [ -L "$HOME/.claude/skills/pack-gstack-browser/skills/qa" ]
# gstack = the three packs; "on" = pack-gstack-dev on for this project and
# conversation. PROFILE_PLAIN (session-start) avoids a second profile.sh run.
local plain="${PROFILE_PLAIN:-}"
[ -n "$plain" ] || plain="$(bash "$HOME/.claude/lib/profile.sh" -C "$PWD" \
current --plain 2>/dev/null)" || return 1
grep -q '^pack-gstack-dev=on' <<<"$plain"
}
detect_gsd() {
+1
View File
@@ -47,6 +47,7 @@ module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
paths = glob.glob(skills_dir + "/*/SKILL.md")
paths += glob.glob(skills_dir + "/pack-*/skills/*/SKILL.md")
chars = sum(len(module.extract_description(p) or "") for p in paths)
print(len(paths), chars)
PY
+19 -73
View File
@@ -8,8 +8,8 @@
# skills, the seven superpowers skills, and any name link.sh links with
# no lock entry at all, e.g. frontend-design, design-motion-principles).
#
# One entry point, `check_vendored_skills <repo> <claude_home>
# [profile_file]`, sourced and called by doctor.sh. Two things checked
# One entry point, `check_vendored_skills <repo> <claude_home>`, sourced
# and called by doctor.sh. Two things checked
# per name in link.sh's EXTERNAL_SKILLS array:
# 1. its file(s) exist under skills-external/<name>/ — expected file
# list comes from the matching plugins.lock.json entry (list shape
@@ -17,13 +17,8 @@
# emil-design-eng single-file "path" shape -> the key itself is the
# name, file "SKILL.md") or, when no lock entry names it at all,
# defaults to ["SKILL.md"].
# 2. when the name is listed in <profile_file> (or no <profile_file>
# is passed — the "could not resolve the active profile" case),
# the <claude_home>/skills/<name> symlink points at
# <repo>/skills-external/<name>. A name absent from the profile is
# reported parked, not failed — unless its lock entry is
# "always_on": true (the superpowers entry is), in which case the
# symlink is checked regardless of the profile (see _dv_check_link).
# 2. the <claude_home>/skills/<name> symlink points at
# <repo>/skills-external/<name>.
#
# Lock parsing via python3 argv (never string-spliced) — same pattern as
# lib/vendor-skills.sh's _vendor_read_lock. link.sh's EXTERNAL_SKILLS
@@ -33,9 +28,7 @@
# Every name/file pulled from the lock or link.sh is spliced into a
# filesystem path (skills-external/<name>/<file>,
# <claude_home>/skills/<name>): _dv_valid_item_name allowlists it first
# (a rejection is a warn + skip, never a fail). doctor.sh's active
# profile splices into lib/profiles/<name>.profile the same way, guarded
# by _dv_valid_profile_name.
# (a rejection is a warn + skip, never a fail).
#
# No `set -euo pipefail` here (mirrors lib/vendor-skills.sh): a sourced
# lib must not change the caller's shell options.
@@ -64,7 +57,7 @@ fi
# _dv_lock_expectations <lockfile> — prints "<name>\t<file>" for every
# skill named under a plugins.lock.json entry whose "managed_by" is
# "curl", plus a THIRD column "\t1" when that entry is "always_on": true
# (the superpowers entry is) — read by _dv_is_always_on, ignored by the
# (the superpowers entry is), ignored by the
# $1==n {print $2} awk in _dv_check_files: a bare list defaults each name
# to ["SKILL.md"]; a dict names its own per-skill file list; an entry
# with neither (the emil-design-eng single-file "path" shape) is itself
@@ -145,22 +138,6 @@ _dv_link_names() {
| grep -v '^$'
}
# _dv_profile_has <profile_file> <name> — true when a line's FIRST
# whitespace-separated token equals <name> (the profile line's label
# column — comments and the type column are ignored).
_dv_profile_has() {
local profile_file="$1" name="$2"
awk -v n="$name" '$1 == n { found=1 } END { exit !found }' "$profile_file"
}
# _dv_valid_profile_name <name> — true when <name> matches the
# profile-name allowlist (letters, digits, underscore, hyphen only).
# <name> is spliced into "lib/profiles/<name>.profile" by doctor.sh, so
# a path-traversal or separator character must never reach it.
_dv_valid_profile_name() {
[[ "$1" =~ ^[A-Za-z0-9_-]+$ ]]
}
# _dv_valid_item_name <name> — true when <name> (a skill name from
# link.sh's EXTERNAL_SKILLS array, or a relative file named by a
# plugins.lock.json entry) matches the item-name allowlist (letters,
@@ -202,59 +179,28 @@ allowlist — skipped"
[ "$all_ok" -eq 1 ]
}
# _dv_is_always_on <name> <lock_out> — true when <lock_out> (the
# "<name>\t<file>[\t1]" lines from _dv_lock_expectations) carries the
# always_on third column for <name>'s lock entry.
_dv_is_always_on() {
local name="$1" lock_out="$2"
awk -F'\t' -v n="$name" '$1 == n && $3 == 1 { found=1 } \
END { exit !found }' <<< "$lock_out"
}
# _dv_check_link <claude_home> <repo> <name> <profile_file> <always_on> —
# when <always_on> is "1" (the name's lock entry is "always_on": true),
# the symlink is checked whatever <profile_file> says — never parked.
# Otherwise, when <profile_file> is non-empty and does not list <name>,
# reports it parked (info), not failed. Otherwise (listed, always_on, or
# no <profile_file> was passed — active profile could not be resolved,
# every external is then expected linked) checks the
# <claude_home>/skills/<name> symlink points at
# <repo>/skills-external/<name>.
# _dv_check_link <claude_home> <repo> <name> — the
# <claude_home>/skills/<name> symlink points at <repo>/skills-external/<name>.
_dv_check_link() {
local claude_home="$1" repo="$2" name="$3" profile_file="$4" \
always_on="$5"
local link target label
if [ "$always_on" != "1" ] && [ -n "$profile_file" ] \
&& ! _dv_profile_has "$profile_file" "$name"; then
label="$(basename "$profile_file" .profile)"
info "$name: parked by profile $label"
return
fi
link="$claude_home/skills/$name"
target="$repo/skills-external/$name"
local claude_home="$1" repo="$2" name="$3"
local link="$claude_home/skills/$name"
local target="$repo/skills-external/$name"
if [ -L "$link" ] && [ "$(readlink "$link")" = "$target" ]; then
pass "$name: vendored + linked"
else
fail "$name: symlink missing/wrong — run: make link (or: bash \
lib/profile.sh apply <profile>)"
fail "$name: symlink missing/wrong — run: make link"
fi
}
# _dv_check_name <repo> <claude_home> <name> <profile_file> <lock_out> —
# per-name dispatch for check_vendored_skills's loop: files first (the
# link check runs only when every expected file is present, same as
# before), then the symlink, passing _dv_is_always_on's verdict as
# _dv_check_link's 5th param.
# _dv_check_name <repo> <claude_home> <name> <lock_out> — per-name
# dispatch: files first, the symlink only when every file is present.
_dv_check_name() {
local repo="$1" claude_home="$2" name="$3" profile_file="$4" lock_out="$5"
local always_on=""
_dv_is_always_on "$name" "$lock_out" && always_on=1
local repo="$1" claude_home="$2" name="$3" lock_out="$4"
_dv_check_files "$repo" "$name" "$lock_out" \
&& _dv_check_link "$claude_home" "$repo" "$name" "$profile_file" \
"$always_on"
&& _dv_check_link "$claude_home" "$repo" "$name"
}
# check_vendored_skills <repo> <claude_home> [profile_file] — see the
# check_vendored_skills <repo> <claude_home> — see the
# file header. Either the lock or link.sh being unreadable (or a
# malformed lock entry — _dv_lock_expectations rc 1) is a warn, never a
# fail; link.sh unreadable skips the whole check (there is nothing to
@@ -262,7 +208,7 @@ _dv_check_name() {
# allowlist before it is spliced into a path — a rejected one is
# warned and skipped, not failed.
check_vendored_skills() {
local repo="$1" claude_home="$2" profile_file="${3:-}"
local repo="$1" claude_home="$2"
local lock_out names name
if ! lock_out="$(_dv_lock_expectations "$repo/plugins.lock.json")"; then
@@ -285,6 +231,6 @@ check skipped"
item-name allowlist — skipped"
continue
fi
_dv_check_name "$repo" "$claude_home" "$name" "$profile_file" "$lock_out"
_dv_check_name "$repo" "$claude_home" "$name" "$lock_out"
done <<< "$names"
}
+11 -60
View File
@@ -3,25 +3,19 @@
# check_vendored_skills(): a fixture repo under mktemp with a fake
# plugins.lock.json (single-path shape, list shape, dict shape with a
# references/ file), a fake link.sh holding a multi-line
# EXTERNAL_SKILLS=(...) array, a fake <claude_home>/skills dir and a fake
# profile file. Cases: every file present + linked (ALL_PRESENT), a
# EXTERNAL_SKILLS=(...) array and a fake <claude_home>/skills dir. Cases: every file present + linked (ALL_PRESENT), a
# list-shape skill missing its SKILL.md (FILE_MISSING), a dict-shape
# skill missing one of two files — only that file is named
# (DICT_FILES_COMPLETE), a profile-listed name with no symlink
# (SYMLINK_MISSING_ACTIVE) or a symlink to the wrong target
# (SYMLINK_WRONG_TARGET), a name absent from the profile reported parked
# rather than failed (SYMLINK_PARKED), the same name treated as
# expected-linked (fail, not parked) when no profile file is passed at
# all (NO_PROFILE_EXPECTS_LINK), an unreadable lock file degrading to a
# (SYMLINK_WRONG_TARGET), an unreadable lock file degrading to a
# warn instead of a fail (LOCK_UNREADABLE, rc 0), a lock entry whose
# "skills" is neither null/list/dict degrading the same way with no
# Python traceback leaking (LOCK_MALFORMED_ENTRY, rc 0), the
# profile-name allowlist rejecting a path-traversal value
# (REJECTS_BAD_PROFILE_NAME), the item-name allowlist rejecting a
# item-name allowlist rejecting a
# link.sh entry with a ".." segment — warned and skipped, not failed
# (REJECTS_BAD_NAME), and an "always_on": true lock entry's name, absent
# from the profile and with no symlink, checked (and failed) instead of
# reported parked (ALWAYS_ON_LINK_CHECKED).
# (REJECTS_BAD_NAME), and an "always_on": true lock entry's name with no
# symlink failing like any other (ALWAYS_ON_LINK_CHECKED).
set -u
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
LIB="$ROOT/lib/doctor-vendored.sh"
@@ -52,8 +46,7 @@ cat > "$REPO/plugins.lock.json" <<'JSON'
"list-entry": {
"managed_by": "curl",
"skills": [
"missing-skill", "active-nolink-skill", "active-wronglink-skill",
"parked-skill", "noprofile-skill"
"missing-skill", "active-nolink-skill", "active-wronglink-skill"
]
},
"dict-entry": {
@@ -72,43 +65,28 @@ JSON
cat > "$REPO/link.sh" <<'SH'
#!/usr/bin/env bash
EXTERNAL_SKILLS=(ok-skill missing-skill dict-skill
active-nolink-skill active-wronglink-skill
parked-skill noprofile-skill always-on-skill)
active-nolink-skill active-wronglink-skill always-on-skill)
SH
# ── skills-external/ tree: every name's SKILL.md present, except
# missing-skill (nothing at all) and dict-skill's references/notes.md.
# always-on-skill has its SKILL.md too — only its symlink is missing.
for n in ok-skill dict-skill active-nolink-skill active-wronglink-skill \
parked-skill noprofile-skill always-on-skill; do
always-on-skill; do
mkdir -p "$REPO/skills-external/$n"
echo "v1" > "$REPO/skills-external/$n/SKILL.md"
done
# ── claude_home symlinks: ok-skill correct, active-wronglink-skill
# points elsewhere, active-nolink-skill, noprofile-skill and
# always-on-skill have none.
# points elsewhere, active-nolink-skill and always-on-skill have none.
ln -sf "$REPO/skills-external/ok-skill" "$CLAUDE_HOME/skills/ok-skill"
mkdir -p "$WORK/elsewhere"
ln -sf "$WORK/elsewhere" "$CLAUDE_HOME/skills/active-wronglink-skill"
# ── active.profile: lists everything EXCEPT parked-skill,
# noprofile-skill and always-on-skill (all three proven absent from it).
cat > "$REPO/active.profile" <<'PROF'
# DESC: fixture profile
ok-skill external
missing-skill external
dict-skill external
active-nolink-skill external
active-wronglink-skill external
PROF
# shellcheck source=../doctor-vendored.sh disable=SC1091
source "$LIB"
# ── With the active profile passed ──────────────────────────────────
out1="$(check_vendored_skills "$REPO" "$CLAUDE_HOME" \
"$REPO/active.profile" 2>&1)"
out1="$(check_vendored_skills "$REPO" "$CLAUDE_HOME" 2>&1)"
check_bool ALL_PRESENT \
"$(printf '%s' "$out1" | grep -qF 'ok-skill: vendored + linked' \
@@ -135,28 +113,9 @@ check_bool SYMLINK_WRONG_TARGET \
grep -qF 'active-wronglink-skill: symlink missing/wrong' \
&& echo 1 || echo 0)"
check_bool SYMLINK_PARKED \
"$(printf '%s' "$out1" | grep -qF 'parked-skill: parked by profile active' \
&& ! printf '%s' "$out1" | \
grep -qF 'parked-skill: symlink missing/wrong' \
&& echo 1 || echo 0)"
# ── always-on-skill: absent from active.profile (same as parked-skill)
# but its lock entry is "always_on": true — checked (and failed, no
# symlink) instead of reported parked.
check_bool ALWAYS_ON_LINK_CHECKED \
"$(printf '%s' "$out1" | \
grep -qF 'always-on-skill: symlink missing/wrong' \
&& ! printf '%s' "$out1" | \
grep -qF 'always-on-skill: parked by profile' \
&& echo 1 || echo 0)"
# ── No profile file passed at all: noprofile-skill (absent from
# active.profile, parked above) must now be treated as expected-linked.
out2="$(check_vendored_skills "$REPO" "$CLAUDE_HOME" 2>&1)"
check_bool NO_PROFILE_EXPECTS_LINK \
"$(printf '%s' "$out2" | \
grep -qF 'noprofile-skill: symlink missing/wrong' && echo 1 || echo 0)"
grep -qF 'always-on-skill: symlink missing/wrong' && echo 1 || echo 0)"
# ── LOCK_UNREADABLE — a second, minimal fixture with an invalid
# plugins.lock.json: check_vendored_skills degrades to a warn (not a
@@ -203,14 +162,6 @@ check_bool LOCK_MALFORMED_ENTRY \
&& ! printf '%s' "$out4" | grep -q 'Error:' \
&& echo 1 || echo 0)"
# ── REJECTS_BAD_PROFILE_NAME — the profile-name allowlist helper
# rejects a path-traversal value and accepts a plain one.
check_bool REJECTS_BAD_PROFILE_NAME \
"$( { _dv_valid_profile_name "full" \
&& ! _dv_valid_profile_name "../x" \
&& ! _dv_valid_profile_name "a/b" \
&& ! _dv_valid_profile_name "a.b"; } && echo 1 || echo 0)"
# ── REJECTS_BAD_NAME — a link.sh EXTERNAL_SKILLS entry with a ".."
# segment: warned and skipped, never reaches _dv_check_files/
# _dv_check_link (no fail line names it), rc 0.
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# lib/tests/statusline.test.sh — hooks/statusline.sh profile segment comes
# from `profile.sh -C <project_dir> current --plain`; a --settings
# conversation shows "(conv)"; profile.sh failing or missing prints
# "profile: ?" and never breaks the line.
set -u
unset CLAUDE_PROFILE CLAUDE_PROFILE_SETTINGS
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
pass=0; fail=0
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/hooks" "$FX/lib" "$FX/proj" "$FX/cwd"
cp "$ROOT/hooks/statusline.sh" "$FX/hooks/"
printf '{"effortLevel": "high"}\n' > "$FX/settings.json"
cat > "$FX/lib/profile.sh" <<'PROF'
#!/usr/bin/env bash
[ "$2" = "$FAKE_DIR" ] || { echo "wrong -C: $2" >&2; exit 2; }
printf 'profile=%s\nsource=%s\n' "$FAKE_PROFILE" "$FAKE_SOURCE"
PROF
# The project dir differs from the cwd: the segment must follow project_dir.
sl() { printf '{"cwd": "%s", "workspace": {"project_dir": "%s"}}\n' \
"$FX/cwd" "$FX/proj" | FAKE_DIR="$FX/proj" bash "$FX/hooks/statusline.sh"; }
out="$(FAKE_PROFILE=web FAKE_SOURCE=local sl)"; check_has T1-local "$out" "profile: web |"
out="$(FAKE_PROFILE=dev FAKE_SOURCE=flag sl)"; check_has T2-conv "$out" "profile: dev (conv) |"
out="$(FAKE_PROFILE=full FAKE_SOURCE=default sl)"; check_has T3-default "$out" "profile: full |"
printf 'exit 2\n' > "$FX/lib/profile.sh"
out="$(sl 2>&1)"; check_has T4-failing "$out" "profile: ? |"
rm "$FX/lib/profile.sh"; out="$(sl 2>&1)"; check_has T5-missing "$out" "profile: ? |"
printf 'PASS=%s FAIL=%s\n' "$pass" "$fail"; [ "$fail" -eq 0 ]