#!/usr/bin/env sh set -e echo "▶ pre-commit: vue-tsc --noEmit" pnpm exec vue-tsc --noEmit echo "▶ pre-commit: pnpm test (vitest)" pnpm test echo "▶ pre-commit: check no figma-data/ sync-output writes" # Block only pure sync extract output (raw figma data + tokenize/normalize/icon # generator output + MCP cache). These are auto-regenerated by sync pipeline; # human edits get silently overwritten. Allows: figma-to-code-mapping.json # (human-maintained), audit-allowlist/, audit reports (*.audit.json), # docs-figma-members/ (derivative data modules), figma-styles.json (post- # EXTRACT-006 pipeline output, downstream-consumed by translation layer — # legitimate to commit since src/tokens/variables.css + token-aliases.ts need it). FIGMA_DATA_BLOCK_PATTERN='^figma-data/(raw/|published/|normalized/(figma-mcp-cache/|components-tokenized|variables\.json))' if git diff --cached --name-only --diff-filter=AM | grep -qE "$FIGMA_DATA_BLOCK_PATTERN"; then echo "" echo "❌ figma-data/ sync-output 写入被 pre-commit hook 阻断" echo " (AGENTS.md 硬规则 #1:figma 真源镜像,sync pipeline 单向写入)" echo " 被阻断的路径模式:" echo " - figma-data/raw/ (raw figma extracts)" echo " - figma-data/published/ (export-icons output)" echo " - figma-data/normalized/figma-mcp-cache/ (MCP cache)" echo " - figma-data/normalized/components-tokenized* (tokenize output)" echo " - figma-data/normalized/variables.json (normalize output)" echo "" echo " 允许(human-maintained / audit reports / downstream-consumed):" echo " - figma-data/figma-to-code-mapping.json (mapping config)" echo " - figma-data/audit-allowlist/ (audit allowlists)" echo " - figma-data/normalized/figma-styles.json (EXTRACT-006 pipeline output; translation/token-aliases.ts 引用)" echo " - figma-data/normalized/*.audit.json (audit reports)" echo " - figma-data/normalized/tokenized-diff-report.json" echo " - figma-data/normalized/docs-figma-members/ (data modules)" echo "" echo " 如确认要 commit sync-output,使用 git commit --no-verify 显式绕过" exit 1 fi echo "▶ pre-commit: visual/design commit approval check" if git diff --cached --name-only --diff-filter=AM | grep -qE '\.(html|css|svg|vue|jsx|tsx)$'; then if [ -z "$VISUAL_COMMIT_APPROVED" ]; then echo "" echo "❌ Visual/design 文件 staged (.html / .css / .svg / .vue / .jsx / .tsx)" echo " 未设置 VISUAL_COMMIT_APPROVED 环境变量" echo "" echo " Why: AI auto-commits 视觉改动 without user 审 = 反复绕弯反模式" echo " (2026-05-13 retrospection: v6/v7 logo 多轮 push back)" echo "" echo " 要 commit 时显式声明(用户已 explicit 看过 + approve 视觉效果):" echo " VISUAL_COMMIT_APPROVED=1 git commit ..." exit 1 fi echo " ✓ VISUAL_COMMIT_APPROVED set, visual commit allowed" fi echo "✅ pre-commit gates passed"