--- name: pre-commit-check description: "MANDATORY pre-commit validation executor. Runs all required checks before any commit. NOT optional - must be invoked before every git add/commit/PR." version: "2.0.0" author: "SublinkPro Team" user-invocable: true mandatory: true enforcement-level: "blocking" --- # Pre-Commit Check Skill **🛑 MANDATORY VALIDATION EXECUTOR 🛑** This skill is **NOT** a suggestion or checklist. It is a **MANDATORY EXECUTION REQUIREMENT**. ## Critical Rules 1. **Invoke this skill BEFORE any `git add`, `git commit`, or PR creation** 2. **Execute ALL applicable validation commands** 3. **Fix ALL failures before proceeding** 4. **Document what was validated in commit message** 5. **Stage changes only after validation passes** 6. **Present to user for final verification (do NOT auto-commit)** ## When to Use This Skill **MANDATORY** invocation before: - Any `git add` command - Any `git commit` command - Any `gh pr create` or PR update command - Declaring work "complete", "done", or "finished" - User requests commit (even if they say "skip checks") **This skill is BLOCKING** - you cannot proceed to commit without invoking it and ensuring all checks pass. ## Skill Execution Protocol When this skill is invoked, you **MUST** follow this exact sequence: ### Step 1: Identify Changed Files ```bash git status --short git diff --name-only git diff --cached --name-only ``` Categorize changes: - [ ] Backend files (*.go) - [ ] Frontend files (webs/*) - [ ] Documentation files (*.md) - [ ] Configuration files (config.yaml, .env.example, etc.) - [ ] Mixed (multiple categories) ### Step 2: Execute Backend Validation (if .go files changed) #### 2.1 Format Check ```bash gofmt -l $(find . -name "*.go" -not -path "./vendor/*" -not -path "./webs/*" -not -path "./.git/*") ``` **If output is not empty**: ```bash gofmt -w $(find . -name "*.go" -not -path "./vendor/*" -not -path "./webs/*" -not -path "./.git/*") ``` **Verify**: ```bash gofmt -l $(find . -name "*.go" -not -path "./vendor/*" -not -path "./webs/*" -not -path "./.git/*") ``` **BLOCKING**: Must return empty output (all files formatted). #### 2.2 Lint Check ```bash golangci-lint run ``` **BLOCKING**: Must exit with status 0. **If fails**: Read the errors, fix them, and re-run. Do NOT proceed until clean. #### 2.3 Test Execution ```bash go test ./... ``` **BLOCKING**: Must exit with status 0 (all tests pass). **If fails**: Read the test output, fix the failing tests or code, and re-run. Do NOT proceed until green. ### Step 3: Execute Frontend Validation (if webs/* files changed) #### 3.1 Lint Check ```bash cd webs && yarn run lint ``` **BLOCKING**: Must exit with status 0. **If fails**: Try auto-fix first: ```bash cd webs && yarn run lint:fix cd webs && yarn run prettier ``` Then re-run `yarn run lint`. Do NOT proceed until clean. #### 3.2 Build Check (if applicable) **Run build if changes affect**: - Routing configuration (`src/routes/*`) - Asset paths or imports (`src/assets/*`, `public/*`) - Base path behavior (`SUBLINK_WEB_BASE_PATH`) - Build configuration (`vite.config.js`, `package.json`) - Major UI components (`src/views/*`, `src/layout/*`) ```bash cd webs && yarn run build ``` **BLOCKING**: Must complete successfully. **If fails**: Read the build error, fix it, and re-run. Do NOT proceed until build succeeds. ### Step 4: Cross-Layer Sync Verification (if multi-layer change) **Trigger condition**: Changes affect both backend AND frontend, OR code AND documentation. **Verification checklist**: - [ ] Backend API endpoint changed → Frontend API client updated (`webs/src/api/*`) - [ ] Backend response structure changed → Frontend types/interfaces updated - [ ] Frontend behavior changed → Backend supports new flow - [ ] Configuration option added/changed → Code + docs + examples updated **If complex cross-layer change**: Invoke `.agents/skills/cross-layer-sync/SKILL.md` for detailed verification. ### Step 5: Documentation Sync Verification (if docs should be updated) **Trigger condition**: Changes affect user-visible behavior, APIs, configuration, or deployment. **Verification checklist**: - [ ] User-facing feature changed → `README.md` + `README.zh-CN.md` updated - [ ] API endpoint changed → `skill-sublinkpro/reference/api.md` updated - [ ] Configuration changed → `docs/configuration.md` + `.zh-CN.md` updated - [ ] Deployment changed → `docs/installation.md` + `.zh-CN.md` + `skill-sublinkpro/reference/deploy.md` updated - [ ] Both language versions updated (bilingual requirement) - [ ] Links verified (no broken references) **If complex doc changes**: Invoke `.agents/skills/doc-sync-check/SKILL.md` for detailed verification. ### Step 6: Test Coverage Verification (if key logic changed) **Trigger condition**: Changes affect business logic, APIs, permissions, migrations, scheduled tasks, or protocol parsing. **Verification checklist**: - [ ] New business logic → Tests added - [ ] Changed behavior → Tests updated - [ ] Bug fix → Regression test added - [ ] API handler changed → Handler tests added/updated - [ ] Permission check changed → Permission tests added/updated **If tests missing**: Add them now. Do NOT proceed without tests for key logic changes. ### Step 7: Git Staging Verification ```bash git status git diff --cached --stat git diff --cached --name-only ``` **Verification checklist**: - [ ] Only intended files staged - [ ] No `.env` files staged - [ ] No credential files staged - [ ] No `db/` directory staged - [ ] No `logs/` directory staged - [ ] No `cache/` directory staged - [ ] No `out/` directory staged - [ ] No large binary files unintentionally staged - [ ] No AI agent temporary files staged: - No `*_SUMMARY.md` files (e.g., `PRE_COMMIT_ENFORCEMENT_SUMMARY.md`) - No `*_REPORT.md` files - No `QUICK_REFERENCE.md` files in skill directories - No `.claude/projects/`, `.claude/sessions/`, `.claude/plans/` files - No agent execution logs or temporary outputs **If unintended files staged**: ```bash git reset HEAD # Unstage unintended files ``` **AI agent temporary files should NEVER be committed**: - These are execution artifacts, not project documentation - They pollute the repository - They are regenerated on each execution - Add them to `.gitignore` if they keep appearing ### Step 8: Commit Message Preparation Prepare a semantic commit message following this format: ``` ():