Files
2nd/10_Wiki/Topic_Programming/DevOps_and_Security/Husky.md
T
Antigravity Agent 9148c358d0 docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
2026-07-05 00:33:48 +09:00

5.4 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-husky Husky 10_Wiki/Topics verified self
Husky Git Hooks
husky v9
lint-staged
pre-commit
none A 0.95 applied
git
hooks
devex
ci
lint-staged
2026-05-10 pending
language framework
javascript husky-v9

Husky

매 한 줄

"매 npm-friendly git hooks 의 facto-standard". Husky 는 매 .husky/ directory 안에 매 plain shell script 로 hook 정의 — 매 git config core.hooksPath 으로 자동 설정. 매 v9 (2024-2026) 부터 매 거의 zero-config: npx husky init → 매 husky/_/h prepare-commit-msg 등 매 wrapper 자동 생성. 매 lint-staged 와의 매 pairing 이 매 표준 setup.

매 핵심

매 핵심 개념

  • core.hooksPath = .husky/_: Husky 가 매 이 path 로 git 을 redirect — 매 user 의 매 hook script 와 매 husky framework script 분리.
  • Plain shell: 매 .husky/pre-commit 의 매 첫 line shebang 없이 — Husky v9 가 매 _/h wrapper 통해 실행.
  • Skip via env: HUSKY=0 또는 HUSKY_SKIP_HOOKS=1 — 매 CI 또는 emergency commit.
  • prepare script: package.json"prepare": "husky" 가 매 install 시 자동 setup.

매 lint-staged 와의 결합

  • 매 staged files 만 lint/format → 매 commit 속도 ↑.
  • 매 prettier --write + eslint --fix + 매 자동 re-stage.
  • 매 large monorepo 에서도 매 fast (only changed paths).

매 hook 우선순위 (자주 쓰는)

  1. pre-commit: lint-staged + type-check (changed only).
  2. commit-msg: commitlint (Conventional Commits 검증).
  3. pre-push: full test suite + build smoke.
  4. post-merge: pnpm install if package.json changed.

💻 패턴

Initial setup

# in repo root
pnpm add -D husky lint-staged
pnpm pkg set scripts.prepare="husky"
pnpm prepare
npx husky init   # creates .husky/pre-commit with `npm test` placeholder

.husky/pre-commit (lint-staged + type-check)

npx lint-staged
pnpm exec tsc --noEmit

lint-staged config (package.json)

{
  "lint-staged": {
    "*.{ts,tsx,js,jsx}": [
      "eslint --fix --max-warnings=0",
      "prettier --write"
    ],
    "*.{json,md,yml,yaml}": ["prettier --write"],
    "*.css": ["stylelint --fix", "prettier --write"]
  }
}

.husky/commit-msg (commitlint)

npx --no -- commitlint --edit "$1"
// commitlint.config.js
module.exports = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'subject-max-length': [2, 'always', 100],
    'scope-enum': [2, 'always', ['ui', 'api', 'docs', 'ci', 'deps']],
  },
};

.husky/pre-push (test + build)

pnpm test --run --silent
pnpm build

Skip in CI / emergency

# CI: prepare script no-op when not in dev install
# package.json
{
  "scripts": {
    "prepare": "node -e \"if (process.env.CI) process.exit(0)\" && husky"
  }
}

# Emergency commit (use sparingly)
HUSKY=0 git commit -m "hotfix: critical patch"
# or
git commit --no-verify -m "..."

Monorepo: only run hooks if relevant

# .husky/pre-commit
CHANGED=$(git diff --cached --name-only)
echo "$CHANGED" | grep -q "^apps/web/" && (cd apps/web && pnpm lint-staged)
echo "$CHANGED" | grep -q "^apps/api/" && (cd apps/api && pnpm lint-staged)

Conditional hook based on branch

# .husky/pre-push
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$BRANCH" = "main" ]; then
  pnpm test --run
  pnpm build
else
  pnpm test --run --bail=1
fi

Adopt in existing repo

# After cloning, dependencies need install to run 'prepare'
pnpm install   # triggers `prepare` → husky sets core.hooksPath
git config --get core.hooksPath   # → .husky/_

Husky + pnpm workspaces filter

# .husky/pre-commit
STAGED=$(git diff --cached --name-only)
PKGS=$(echo "$STAGED" | awk -F/ '/^packages\// {print $2}' | sort -u)
for p in $PKGS; do
  pnpm --filter "@repo/$p" lint-staged
done

매 결정 기준

상황 Approach
TS/JS project Husky v9 + lint-staged
Polyglot (Python, Go) pre-commit framework (multi-lang)
Heavy hooks (>10s) move to pre-push, lighten pre-commit
Solo dev hobby optional — lint in CI alone may suffice
Enterprise enforcement husky + commitlint + branch protection

기본값: 매 TS/JS team — Husky v9 + lint-staged + commitlint.

🔗 Graph

🤖 LLM 활용

언제: 매 hook script 작성, lint-staged config 생성, commitlint rule 제안, monorepo conditional logic. 언제 X: 매 binary install verification — local 환경에서 매 직접 실행.

안티패턴

  • 30s pre-commit: 매 dev 가 매 --no-verify 습관화 → 매 hook 무용지물.
  • Run full test in pre-commit: 매 pre-push 로 옮기기.
  • No CI fallback: 매 hook 만 신뢰 → 매 --no-verify bypass 시 dirty commit.
  • Husky 의 commit hook 안 비밀 커밋 검증 누락: 매 detect-secrets / gitleaks pairing.
  • Per-developer husky version drift: 매 lockfile pin 필수.

🧪 검증 / 중복

  • Verified (Husky v9 docs 2026, lint-staged v15+).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — Husky v9 + lint-staged + commitlint patterns