Files
claude_mac/hooks/design-toolchain-reminder.sh
T
bchanot 381ed9fa5d chore(code-clean): lint directives, guarded cd, hook regex split, helper extractions
A1 drop unused `import gzip`; B1/B2 file-level shellcheck directives
placed before `set -u`; B3 `cd "$REPO" || exit 1`; B4 hook regex split
into `pattern+=` lines (sha256 of $pattern unchanged); B11
`_build_parser`/`_dispatch` pulled out of google_seo `_cli`; B20
detect-plugins header names update-all.sh; C2 prune-memory deterministic
suite wired into SUITES (literal path); C3 `_refuse_outside_allowlist`
moved up in deploy-commit.

No behavior change except B3 (a failed cd now exits 1) and C2 (one more
suite). B5/B7/B9/B18/B19 land in the refactor commit.
2026-10-12 22:51:28 +02:00

80 lines
4.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# design-toolchain-reminder.sh
#
# UserPromptSubmit hook. When the prompt carries a UI/design signal, inject a
# reminder to mobilize the full design toolchain (tiered by scope, per CLAUDE.global.md
# "Design work — full toolchain"). A UserPromptSubmit hook's stdout is appended
# to the model's context, so the cat block below becomes additional guidance.
#
# This is a soft nudge: the tiered rule itself says trivial work uses NO
# toolchain, so a false positive (e.g. "API design") costs only a reminder the
# model can disregard. Always exits 0 so it never blocks prompt submission.
#
# Every fire appends one line (time, matched token, prompt excerpt) to
# ~/.claude/logs/design-toolchain-fires.log — a counter so the next "is it
# over-firing?" decision is measured, not anecdotal.
set -euo pipefail
input="$(cat)"
# Extract the user's prompt from the hook JSON; fall back to the raw stdin if
# python or the expected field is unavailable.
prompt="$(printf '%s' "$input" \
| python3 -c 'import sys, json; print(json.load(sys.stdin).get("prompt", ""))' \
2>/dev/null || true)"
[ -z "$prompt" ] && prompt="$input"
# Harness-generated turns (subagent/task notifications) are not user
# requests — never fire on them (CLAUDE.global.md trigger = a design/UI *request*).
case "$prompt" in
'<task-notification>'*) exit 0 ;;
esac
lc="$(printf '%s' "$prompt" | tr '[:upper:]' '[:lower:]')"
# UI/design build and review signals (FR + EN). Word boundaries (\b) avoid
# substring false matches like perform/platform/information.
# Tightened 2026-07-02: dropped ultra-generic tokens (page, form, menu, card,
# style, look, screen, interface, color) that fired on non-UI prompts.
# Tightened again 2026-07-03: dropped bare design|component|composant|theme|
# thème|transition|frontend|front-end|palette — all common in non-UI technical
# talk (a design decision, a system component, the theme of a discussion, a
# state transition, frontend architecture). Kept as UI-specific compounds:
# "design system", "redesign", "front-?end design". dashboard -> \bdashboard\b
# so a filename like ecc_dashboard.py no longer matches while "admin dashboard"
# still does. animation kept (rarely non-UI).
# Tightened 2026-07-30 (3rd pass): dropped \bux\b — bare "ux" matched inside
# French prose ("changement ux vu…"; 2 logged FPs, both FR). \bui\b KEPT
# (zero logged FP, one logged true positive). NB: the log records only the
# FIRST match per fire (head -1), so per-token FP rates aren't derivable.
pattern='redesign|refonte|refont|ui/ux|ux/ui|\bui\b|ui kit|design system'
pattern+='|design-system|front-?end design|\bnavbar\b|\bsidebar\b|\bmodal\b'
pattern+='|\bbouton\b|\bbutton\b|formulaire|\bhero\b|\bheader\b|\bfooter\b'
pattern+='|dropdown|tooltip|\bbadge\b|\bchart\b|graphique|accordion|carousel'
pattern+='|\bslider\b|landing|\bdashboard\b|homepage|home page|\baccueil\b'
pattern+='|\bécran\b|\becran\b|portfolio|maquette|mockup|wireframe|prototype'
pattern+='|\bjoli\b|\bjolie\b|\bbeau\b|\bbelle\b|esth[eé]tique|aesthetic'
pattern+='|\bvisuel\b|\bvisual\b|embellir|fignol|peaufin|polish|styliser'
pattern+='|styling|stylesheet|\bskin\b|charte graphique|\bbrand\b|branding'
pattern+='|\blogo\b|favicon|ic[oô]ne|\bicon\b|\bcss\b|tailwind|shadcn|couleur'
pattern+='|gradient|d[eé]grad[eé]|\bombre\b|spacing|espacement|\bmarge\b'
pattern+='|\bpadding\b|\bmargin\b|\bradius\b|arrondi|\bhover\b|dark mode'
pattern+='|light mode|typograph|\bfont\b|\bfonts\b|font pairing|\bpolice\b'
pattern+='|animation|\bmotion\b|micro-interaction|keyframe|glassmorph|neumorph'
pattern+='|claymorph|skeuomorph|brutalis|bento|minimalis|responsive|figma'
if printf '%s' "$lc" | grep -Eq "$pattern"; then
# Counter: log the fire (time, matched token, excerpt) — best-effort, never blocks.
logf="${HOME}/.claude/logs/design-toolchain-fires.log"
mkdir -p "$(dirname "$logf")" 2>/dev/null || true
printf '%s\t%s\t%s\n' "$(date -Iseconds)" \
"$(printf '%s' "$lc" | grep -oiE "$pattern" | head -1 || true)" \
"$(printf '%s' "$prompt" | tr '\n\t' ' ' | cut -c1-100)" >> "$logf" 2>/dev/null || true
cat <<'EOF'
Design work detected → apply global CLAUDE.md section "Design work — full toolchain" (already in context). Trivial (≤2 files, cosmetic) → /hotfix.
EOF
fi
exit 0