repo-hygiene
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineserepo-hygiene — Repository Health Check
repo-hygiene — 仓库健康检查
A structured, periodic health check for repositories. Run anytime to detect drift,
accumulation of tech debt, and configuration issues before they become problems.
Not a release gate. For pre-release checks, use the skill instead.
This skill is for ongoing maintenance — run it weekly, after major refactors, when
onboarding to a repo, or whenever things feel "off".
pre-release这是一个结构化的仓库定期健康检查方案。可随时运行,在代码漂移、技术债务累积和配置问题演变为严重故障前及时发现它们。
非发布准入检查。若需预发布检查,请使用技能。本技能用于日常维护——可每周运行一次、大型重构后运行、加入新仓库时运行,或是感觉仓库状态「不对劲」时运行。
pre-releaseWhen to Use
适用场景
- Onboarding to a new (or forgotten) repo — "what shape is this in?"
- Weekly/monthly maintenance sweep
- After a large refactor or dependency upgrade
- Before starting a new feature sprint
- When CI starts failing mysteriously
- After a team member leaves and you inherit their repo
- 加入新仓库(或重新接手遗忘已久的仓库)时——「这个仓库当前状态如何?」
- 每周/每月维护巡检
- 大型重构或依赖项升级完成后
- 启动新功能迭代前
- CI系统出现莫名失败时
- 团队成员离职后接手其仓库时
Supported Stacks
支持的技术栈
| Stack | Package manager | Detected by |
|---|---|---|
| Node.js / TypeScript | npm | |
| Python | uv / pip | |
| Go | go modules | |
Detect the stack from the project root. Multiple stacks in one repo is fine — run
applicable checks for each. If the stack isn't listed, skip stack-specific checks
and run the universal ones (git, CI, docs, security).
| 技术栈 | 包管理器 | 检测依据 |
|---|---|---|
| Node.js / TypeScript | npm | |
| Python | uv / pip | |
| Go | Go Modules | |
从项目根目录自动检测技术栈。单个仓库支持多技术栈——会为每个适用的技术栈运行对应检查。若技术栈未在列表中,则跳过栈专属检查,仅运行通用检查(Git、CI、文档、安全)。
The Workflow
工作流程
Step 0: Detect Project
步骤0:检测项目信息
bash
undefinedbash
undefinedWhat are we working with?
识别当前项目类型
ls package.json pyproject.toml go.mod 2>/dev/null
git rev-parse --show-toplevel
Determine: stack(s), git remote, default branch, CI system (GitHub Actions, GitLab CI, etc.).ls package.json pyproject.toml go.mod 2>/dev/null
git rev-parse --show-toplevel
确定:技术栈、Git远程仓库地址、默认分支、CI系统(GitHub Actions、GitLab CI等)。Step 1: Dependency Health
步骤1:依赖项健康检查
Node.js / npm
Node.js / npm
| # | Check | Command | Severity |
|---|---|---|---|
| D1 | Known vulnerabilities | | 🔴 critical/high = Fix Now, moderate = Fix Soon |
| D2 | Outdated dependencies | | 🟡 major bumps = Fix Soon, minor/patch = Info |
| D3 | Unused dependencies | | 🟡 Fix Soon |
| D4 | Phantom dependencies (used but undeclared) | | 🔴 Fix Now |
| D5 | Lockfile freshness | See below | 🟡 Fix Soon |
| D6 | Duplicate dependencies | | ℹ️ Info |
D5 — Lockfile freshness check:
bash
undefined| 编号 | 检查项 | 命令 | 严重程度 |
|---|---|---|---|
| D1 | 已知漏洞 | | 🔴 严重/高危 = 立即修复,中危 = 尽快修复 |
| D2 | 过时依赖项 | | 🟡 大版本更新 = 尽快修复,小版本/补丁 = 信息提示 |
| D3 | 未使用依赖项 | | 🟡 尽快修复 |
| D4 | 幽灵依赖项(已使用但未声明) | | 🔴 立即修复 |
| D5 | 锁文件新鲜度 | 见下方说明 | 🟡 尽快修复 |
| D6 | 重复依赖项 | | ℹ️ 信息提示 |
D5 — 锁文件新鲜度检查:
bash
undefinedpackage.json changed more recently than lockfile?
检查package.json是否比lockfile更新
LOCK_DATE=$(git log -1 --format=%ct -- package-lock.json 2>/dev/null || echo 0)
PKG_DATE=$(git log -1 --format=%ct -- package.json 2>/dev/null || echo 0)
if [ "$PKG_DATE" -gt "$LOCK_DATE" ]; then
echo "⚠️ package.json modified after lockfile — run npm install"
fi
**How to fix:**
- D1: `npm audit fix` for compatible fixes; `npm audit fix --force` for breaking (review changes). For stubborn advisories: check if the vuln is reachable, or override in `package.json` `overrides`.
- D2: `npm update` for minor/patch; `npm install <pkg>@latest` for major (check changelogs).
- D3: `npm uninstall <pkg>` for each unused dep.
- D4: `npm install <pkg>` for each missing dep.
- D5: `npm install` to regenerate lockfile, commit it.
- D6: `npm dedupe` then verify tests pass.LOCK_DATE=$(git log -1 --format=%ct -- package-lock.json 2>/dev/null || echo 0)
PKG_DATE=$(git log -1 --format=%ct -- package.json 2>/dev/null || echo 0)
if [ "$PKG_DATE" -gt "$LOCK_DATE" ]; then
echo "⚠️ package.json修改时间晚于lockfile — 请运行npm install"
fi
**修复方案:**
- D1:运行`npm audit fix`应用兼容修复;使用`npm audit fix --force`应用可能存在破坏性的修复(需仔细审查变更)。对于顽固漏洞:检查漏洞是否可被触发,或在`package.json`的`overrides`中覆盖依赖版本。
- D2:运行`npm update`更新小版本/补丁;运行`npm install <pkg>@latest`更新大版本(需查看变更日志)。
- D3:对每个未使用的依赖项运行`npm uninstall <pkg>`。
- D4:对每个缺失的依赖项运行`npm install <pkg>`。
- D5:运行`npm install`重新生成锁文件并提交。
- D6:运行`npm dedupe`后验证测试是否通过。Python (uv / pip)
Python (uv / pip)
| # | Check | Command | Severity |
|---|---|---|---|
| D1 | Known vulnerabilities | | 🔴 Fix Now |
| D2 | Outdated dependencies | | 🟡 Fix Soon |
| D3 | Unused dependencies | | 🟡 Fix Soon |
| D5 | Lockfile freshness | Compare | 🟡 Fix Soon |
How to fix:
- D1: for each vulnerable package. Check advisories for minimum safe version.
uv pip install --upgrade <pkg> - D2: per package, or
uv pip install --upgrade <pkg>for all.uv lock --upgrade - D3: Remove from in
[project.dependencies], thenpyproject.toml.uv sync - D5: .
uv lock && uv sync
| 编号 | 检查项 | 命令 | 严重程度 |
|---|---|---|---|
| D1 | 已知漏洞 | | 🔴 立即修复 |
| D2 | 过时依赖项 | | 🟡 尽快修复 |
| D3 | 未使用依赖项 | | 🟡 尽快修复 |
| D5 | 锁文件新鲜度 | 对比 | 🟡 尽快修复 |
修复方案:
- D1:对每个存在漏洞的包运行。查看漏洞公告确认最低安全版本。
uv pip install --upgrade <pkg> - D2:对单个包运行,或运行
uv pip install --upgrade <pkg>更新所有依赖。uv lock --upgrade - D3:从的
pyproject.toml中移除未使用的依赖,然后运行[project.dependencies]。uv sync - D5:运行。
uv lock && uv sync
Go
Go
| # | Check | Command | Severity |
|---|---|---|---|
| D1 | Known vulnerabilities | | 🔴 Fix Now |
| D2 | Outdated dependencies | | 🟡 Fix Soon |
| D3 | Unused dependencies | | 🟡 Fix Soon |
How to fix:
- D1: for vulnerable deps, then
go get <module>@latest.go mod tidy - D2: for all, or
go get -u ./...selectively.go get <module>@latest - D3: removes unused; commit
go mod tidyandgo.mod.go.sum
| 编号 | 检查项 | 命令 | 严重程度 |
|---|---|---|---|
| D1 | 已知漏洞 | | 🔴 立即修复 |
| D2 | 过时依赖项 | | 🟡 尽快修复 |
| D3 | 未使用依赖项 | | 🟡 尽快修复 |
修复方案:
- D1:对存在漏洞的依赖运行,然后运行
go get <module>@latest。go mod tidy - D2:运行更新所有依赖,或选择性运行
go get -u ./...。go get <module>@latest - D3:运行移除未使用的依赖,提交
go mod tidy和go.mod。go.sum
Step 2: Git Hygiene
步骤2:Git仓库维护
| # | Check | Command | Severity |
|---|---|---|---|
| G1 | Stale local branches (merged) | | 🟡 Fix Soon |
| G2 | Stale remote branches (merged) | | 🟡 Fix Soon |
| G3 | Large files in repo | See below | 🟡 Fix Soon (🔴 if >10MB) |
| G4 | | See below | 🟡 Fix Soon |
| G5 | Untracked files that should be ignored | | ℹ️ Info |
| G6 | Uncommitted changes | | ℹ️ Info |
G3 — Large files check:
bash
undefined| 编号 | 检查项 | 命令 | 严重程度 |
|---|---|---|---|
| G1 | 已合并的本地 stale 分支 | | 🟡 尽快修复 |
| G2 | 已合并的远程 stale 分支 | | 🟡 尽快修复 |
| G3 | 仓库中的大文件 | 见下方说明 | 🟡 尽快修复(🔴 若文件>10MB) |
| G4 | | 见下方说明 | 🟡 尽快修复 |
| G5 | 应被忽略但未被追踪的文件 | | ℹ️ 信息提示 |
| G6 | 未提交的变更 | | ℹ️ 信息提示 |
G3 — 大文件检查:
bash
undefinedTop 10 largest tracked files
查看前10个最大的已追踪文件
git ls-files -z | xargs -0 -I{} git log --diff-filter=A --format='%H' -1 -- '{}' | head -20
git ls-files -z | xargs -0 -I{} git log --diff-filter=A --format='%H' -1 -- '{}' | head -20
Simpler: just check current tree
简化版:仅检查当前工作树
git ls-files -z | xargs -0 du -sh 2>/dev/null | sort -rh | head -10
**G4 — .gitignore completeness:**
Must include (per stack):
- **Universal**: `.env`, `.env.*`, `*.local`, `.DS_Store`, `Thumbs.db`, `*.swp`, `.idea/`, `.vscode/` (or be deliberate about tracking it)
- **Node**: `node_modules/`, `dist/`, `build/`, `coverage/`, `.turbo/`, `.next/`
- **Python**: `__pycache__/`, `*.pyc`, `.venv/`, `venv/`, `.mypy_cache/`, `.pytest_cache/`, `*.egg-info/`
- **Go**: binary name (check `go build -o`), `vendor/` (if not vendoring)
**How to fix:**
- G1: `git branch -d <branch>` for each merged local branch.
- G2: `git push origin --delete <branch>` for each merged remote branch. Be careful — confirm with team.
- G3: For files that shouldn't be tracked: add to `.gitignore`, `git rm --cached <file>`. For files already in history: `git filter-repo` or BFG Repo-Cleaner (destructive — confirm first).
- G4: Add missing patterns to `.gitignore`. Use a generator like [gitignore.io](https://gitignore.io) as a starting point.
- G5: Either add to `.gitignore` or `git add` if they should be tracked.
---git ls-files -z | xargs -0 du -sh 2>/dev/null | sort -rh | head -10
**G4 — .gitignore完整性:**
需包含以下内容(按技术栈分类):
- **通用**:`.env`, `.env.*`, `*.local`, `.DS_Store`, `Thumbs.db`, `*.swp`, `.idea/`, `.vscode/`(若刻意追踪则除外)
- **Node**:`node_modules/`, `dist/`, `build/`, `coverage/`, `.turbo/`, `.next/`
- **Python**:`__pycache__/`, `*.pyc`, `.venv/`, `venv/`, `.mypy_cache/`, `.pytest_cache/`, `*.egg-info/`
- **Go**:二进制文件名(查看`go build -o`配置)、`vendor/`(若未启用依赖 vendoring)
**修复方案:**
- G1:对每个已合并的本地分支运行`git branch -d <branch>`。
- G2:对每个已合并的远程分支运行`git push origin --delete <branch>`。操作前需谨慎——请与团队确认。
- G3:对于不应被追踪的文件:添加到`.gitignore`,运行`git rm --cached <file>`。对于已存在于历史中的大文件:使用`git filter-repo`或BFG Repo-Cleaner(操作具有破坏性——需先确认)。
- G4:向`.gitignore`添加缺失的规则。可使用[gitignore.io](https://gitignore.io)作为生成起点。
- G5:要么添加到`.gitignore`,要么运行`git add`将其纳入追踪(若属于应追踪文件)。
---Step 3: CI/CD Health
步骤3:CI/CD健康检查
Skip if no CI configuration found.
| # | Check | Command | Severity |
|---|---|---|---|
| C1 | Workflow files exist | | ℹ️ Info |
| C2 | Actions pinned by SHA | | 🟡 Fix Soon |
| C3 | Least-privilege permissions | Scan for | 🟡 Fix Soon |
| C4 | No secret leaks in workflows | Check for | 🔴 Fix Now |
| C5 | Deprecated actions | Check for known deprecated: | 🟡 Fix Soon |
| C6 | Node/Python version matches project | Compare workflow matrix with | 🟡 Fix Soon |
How to fix:
- C2: Replace with
uses: actions/checkout@v4. Find SHA:uses: actions/checkout@<full-sha>or check the releases page.gh api repos/actions/checkout/git/ref/tags/v4 --jq .object.sha - C3: Add explicit at job level. Start with
permissions:and add only what's needed.contents: read - C4: Remove secret interpolation. Use blocks or write to files with masking.
environment: - C5: Replace deprecated actions with current equivalents. →
set-outputfile.$GITHUB_OUTPUT - C6: Align versions. Use or
.nvmrcas the source of truth.engines
若未发现CI配置文件则跳过此步骤。
| 编号 | 检查项 | 命令 | 严重程度 |
|---|---|---|---|
| C1 | 工作流文件是否存在 | | ℹ️ 信息提示 |
| C2 | Actions是否通过SHA固定版本 | | 🟡 尽快修复 |
| C3 | 权限是否遵循最小权限原则 | 扫描 | 🟡 尽快修复 |
| C4 | 工作流中是否存在密钥泄露 | 检查是否有 | 🔴 立即修复 |
| C5 | 是否存在已弃用的Actions | 检查已知弃用项: | 🟡 尽快修复 |
| C6 | Node/Python版本是否与项目匹配 | 对比工作流矩阵与 | 🟡 尽快修复 |
修复方案:
- C2:将替换为
uses: actions/checkout@v4。获取SHA:运行uses: actions/checkout@<完整SHA>或查看Releases页面。gh api repos/actions/checkout/git/ref/tags/v4 --jq .object.sha - C3:在作业级别添加明确的配置。从
permissions:开始,仅添加必要的权限。contents: read - C4:移除密钥插值。使用块或写入带掩码的文件。
environment: - C5:将已弃用的Actions替换为当前等效项。→
set-output文件。$GITHUB_OUTPUT - C6:对齐版本。推荐使用或
.nvmrc作为版本唯一可信源。engines
Step 4: Code Quality Drift
步骤4:代码质量漂移检查
| # | Check | Command | Severity |
|---|---|---|---|
| Q1 | TODO/FIXME/HACK count | | ℹ️ Info (🟡 if >20) |
| Q2 | | | 🟡 Fix Soon |
| Q3 | Disabled/skipped tests | | 🟡 Fix Soon |
| Q4 | Lint passes | | 🟡 Fix Soon |
| Q5 | Tests pass | | 🔴 Fix Now |
| Q6 | Build succeeds | | 🔴 Fix Now |
| Q7 | Type errors (TS) | | 🟡 Fix Soon |
| Q8 | Dead exports (TS) | | ℹ️ Info |
How to fix:
- Q1: Triage each TODO — either do it, create an issue/task for it, or remove it if obsolete.
- Q2: Replace with a proper logger, or remove debug logging. to find them.
grep -rn 'console.log' src/ - Q3: Either fix the underlying issue and un-skip, or delete the test if the feature was removed.
- Q4–Q7: Fix the errors. Run the tool, address each issue.
- Q8: Remove unused exports, or add if they're part of the public API.
// ts-prune-ignore-next
| 编号 | 检查项 | 命令 | 严重程度 |
|---|---|---|---|
| Q1 | TODO/FIXME/HACK数量 | | ℹ️ 信息提示(🟡 若数量>20) |
| Q2 | 源码中存在 | | 🟡 尽快修复 |
| Q3 | 已禁用/跳过的测试用例 | | 🟡 尽快修复 |
| Q4 | 代码检查是否通过 | | 🟡 尽快修复 |
| Q5 | 测试是否通过 | | 🔴 立即修复 |
| Q6 | 构建是否成功 | | 🔴 立即修复 |
| Q7 | TypeScript是否存在类型错误 | | 🟡 尽快修复 |
| Q8 | 是否存在未使用的导出(TS) | | ℹ️ 信息提示 |
修复方案:
- Q1:逐个梳理TODO项——要么立即处理,要么创建议题/任务,若已过时则直接删除。
- Q2:替换为正式日志工具,或移除调试日志。运行定位所有实例。
grep -rn 'console.log' src/ - Q3:要么修复底层问题并重新启用测试,要么删除测试用例(若对应功能已移除)。
- Q4–Q7:修复所有错误。运行对应工具,逐个解决问题。
- Q8:移除未使用的导出,若属于公共API则添加注释。
// ts-prune-ignore-next
Step 5: Documentation Freshness
步骤5:文档新鲜度检查
| # | Check | Command | Severity |
|---|---|---|---|
| F1 | README.md exists | File check | 🔴 Fix Now |
| F2 | README freshness vs. source | Compare | 🟡 if src is >30 days newer |
| F3 | CHANGELOG exists | File check | 🟡 Fix Soon (for published packages) |
| F4 | Broken internal links | See below | 🟡 Fix Soon |
| F5 | LICENSE file present | File check | 🔴 Fix Now |
| F6 | LICENSE matches package metadata | Compare LICENSE text with | 🟡 Fix Soon |
| F7 | AGENTS.md references valid paths | If | 🟡 Fix Soon |
F4 — Broken link check:
bash
undefined| 编号 | 检查项 | 命令 | 严重程度 |
|---|---|---|---|
| F1 | README.md是否存在 | 文件检查 | 🔴 立即修复 |
| F2 | README与源码的新鲜度对比 | 对比 | 🟡 若源码更新时间比README晚30天以上 |
| F3 | CHANGELOG是否存在 | 文件检查 | 🟡 尽快修复(针对已发布的包) |
| F4 | 是否存在内部链接失效 | 见下方说明 | 🟡 尽快修复 |
| F5 | LICENSE文件是否存在 | 文件检查 | 🔴 立即修复 |
| F6 | LICENSE是否与包元数据匹配 | 对比LICENSE文本与 | 🟡 尽快修复 |
| F7 | AGENTS.md是否引用有效路径 | 若 | 🟡 尽快修复 |
F4 — 失效链接检查:
bash
undefinedFind markdown links and verify targets exist
查找Markdown链接并验证目标是否存在
grep -roE '[([^]]+)](([^)]+))' .md docs/**/.md 2>/dev/null |
grep -v 'http' |
while IFS= read -r line; do # Extract path from markdown link path=$(echo "$line" | sed 's/.](([^)]))./\1/' | sed 's/#.//') if [ -n "$path" ] && [ ! -e "$path" ]; then echo "BROKEN: $line" fi done
grep -v 'http' |
while IFS= read -r line; do # Extract path from markdown link path=$(echo "$line" | sed 's/.](([^)]))./\1/' | sed 's/#.//') if [ -n "$path" ] && [ ! -e "$path" ]; then echo "BROKEN: $line" fi done
**How to fix:**
- F1: Write a README with: what it does, how to install, how to use, prerequisites, license.
- F2: Review README against current code — update examples, API docs, feature lists.
- F3: Add a CHANGELOG.md. Consider `@changesets/cli` for automated generation (see `pre-release` skill).
- F4: Update or remove broken links.
- F5: Add a LICENSE file. Use [choosealicense.com](https://choosealicense.com) if unsure.
- F6: Make LICENSE file and metadata agree.
- F7: Update AGENTS.md to reflect current project structure.
---grep -roE '[([^]]+)](([^)]+))' .md docs/**/.md 2>/dev/null |
grep -v 'http' |
while IFS= read -r line; do # 从Markdown链接中提取路径 path=$(echo "$line" | sed 's/.](([^)]))./\1/' | sed 's/#.//') if [ -n "$path" ] && [ ! -e "$path" ]; then echo "失效链接: $line" fi done
grep -v 'http' |
while IFS= read -r line; do # 从Markdown链接中提取路径 path=$(echo "$line" | sed 's/.](([^)]))./\1/' | sed 's/#.//') if [ -n "$path" ] && [ ! -e "$path" ]; then echo "失效链接: $line" fi done
**修复方案:**
- F1:编写README,内容应包含:功能介绍、安装方法、使用方法、前置依赖、许可证。
- F2:对照当前代码审查README——更新示例、API文档、功能列表。
- F3:添加CHANGELOG.md。可考虑使用`@changesets/cli`自动生成(参考`pre-release`技能)。
- F4:更新或移除失效链接。
- F5:添加LICENSE文件。若不确定选择哪种许可证,可使用[choosealicense.com](https://choosealicense.com)。
- F6:确保LICENSE文件与元数据中的许可证信息一致。
- F7:更新AGENTS.md以反映当前项目结构。
---Step 6: Configuration Consistency
步骤6:配置一致性检查
| # | Check | How | Severity |
|---|---|---|---|
| X1 | EditorConfig present | | ℹ️ Info |
| X2 | Strict mode (TS) | | 🟡 Fix Soon |
| X3 | Formatter configured | | 🟡 Fix Soon |
| X4 | Linter configured | | 🟡 Fix Soon |
| X5 | Engine constraints match CI | | 🟡 Fix Soon |
| X6 | | Compare with | ℹ️ Info |
How to fix:
- X1: Add . Minimal:
.editorconfig,root = trueblock with[*],indent_style,indent_size,end_of_line.insert_final_newline - X2: Set in
"strict": true. Fix resulting type errors (usually worth it).tsconfig.json - X3–X4: Add config files. Use the project's existing style as a baseline.
- X5–X6: Pick one source of truth (recommend /
engines) and align everything else.requires-python
| 编号 | 检查项 | 检查方式 | 严重程度 |
|---|---|---|---|
| X1 | 是否存在EditorConfig | | ℹ️ 信息提示 |
| X2 | TypeScript是否启用严格模式 | | 🟡 尽快修复 |
| X3 | 是否配置格式化工具 | 是否存在 | 🟡 尽快修复 |
| X4 | 是否配置代码检查工具 | 是否存在 | 🟡 尽快修复 |
| X5 | 引擎约束是否与CI匹配 | | 🟡 尽快修复 |
| X6 | | 与 | ℹ️ 信息提示 |
修复方案:
- X1:添加。最小配置:
.editorconfig,root = true块包含[*]、indent_style、indent_size、end_of_line。insert_final_newline - X2:在中设置
tsconfig.json。修复由此产生的类型错误(通常值得投入)。"strict": true - X3–X4:添加配置文件。以项目现有代码风格为基准。
- X5–X6:选定一个可信源(推荐/
engines),并对齐所有其他配置。requires-python
Step 7: Security Posture
步骤7:安全态势检查
Lightweight security checks for ongoing hygiene. For the full pre-release security audit
(gitleaks, trufflehog, workflow audit), use the skill.
pre-release| # | Check | Command | Severity |
|---|---|---|---|
| S1 | No tracked | | 🔴 Fix Now |
| S2 | | File check | 🟡 Fix Soon |
| S3 | No hardcoded secrets in source | | 🔴 Fix Now |
| S4 | Secrets scanning config present | | ℹ️ Info |
| S5 | No broad file permissions | Check for | 🔴 Fix Now |
How to fix:
- S1: , add to
git rm --cached <file>, commit. If the file contained real secrets, rotate them immediately — they're in git history..gitignore - S2: Create with placeholder values (
.env.example) for every var in<REPLACE_ME>..env - S3: Move secrets to env vars or a secrets manager. Replace in code with /
process.env.VAR.os.environ["VAR"] - S4: Add (even a minimal one enables CI scanning). Or add
.gitleaks.tomlto pre-commit hooks.gitleaks - S5: Use least-privilege permissions (for files,
644for executables).755
针对日常维护的轻量级安全检查。若需完整的预发布安全审计(gitleaks、trufflehog、工作流审计),请使用技能。
pre-release| 编号 | 检查项 | 命令 | 严重程度 |
|---|---|---|---|
| S1 | 是否存在被追踪的 | | 🔴 立即修复 |
| S2 | 若 | 文件检查 | 🟡 尽快修复 |
| S3 | 源码中是否存在硬编码密钥 | | 🔴 立即修复 |
| S4 | 是否存在密钥扫描配置 | 是否存在 | ℹ️ 信息提示 |
| S5 | 是否存在过宽的文件权限 | 检查脚本中是否存在 | 🔴 立即修复 |
修复方案:
- S1:运行,添加到
git rm --cached <file>,提交变更。若文件包含真实密钥,需立即轮换——因为它们已存在于Git历史中。.gitignore - S2:创建,为
.env.example中的每个变量添加占位值(.env)。<REPLACE_ME> - S3:将密钥迁移到环境变量或密钥管理系统。在代码中替换为/
process.env.VAR。os.environ["VAR"] - S4:添加(即使是最小配置也能启用CI扫描)。或在预提交钩子中添加
.gitleaks.toml。gitleaks - S5:使用最小权限(文件为,可执行文件为
644)。755
Step 8: Project Metadata
步骤8:项目元数据检查
| # | Check | How | Severity |
|---|---|---|---|
| M1 | Required package fields | | 🟡 Fix Soon |
| M2 | Repository URL set | | 🟡 Fix Soon |
| M3 | Keywords present | | ℹ️ Info |
| M4 | | | ℹ️ Info |
| M5 | Pi package compliance | If ships skills/extensions: | 🟡 Fix Soon (if applicable) |
How to fix:
- M1–M3: Add the missing fields to or
package.json.pyproject.toml - M4: Create with
.github/FUNDING.yml.github: <username> - M5: See pi package docs for required fields.
| 编号 | 检查项 | 检查方式 | 严重程度 |
|---|---|---|---|
| M1 | 包必填字段是否完整 | | 🟡 尽快修复 |
| M2 | 是否设置仓库URL | 包元数据中是否存在 | 🟡 尽快修复 |
| M3 | 是否存在关键词 | 是否存在 | ℹ️ 信息提示 |
| M4 | 公共仓库是否存在 | | ℹ️ 信息提示 |
| M5 | 是否符合Pi包规范 | 若包含技能/扩展:是否存在 | 🟡 尽快修复(若适用) |
修复方案:
- M1–M3:向或
package.json添加缺失字段。pyproject.toml - M4:创建,添加
.github/FUNDING.yml。github: <username> - M5:参考Pi包文档补充必填字段。
Baseline Tracking
基线跟踪
Save a baseline after each run to detect drift over time. Store at :
.pi/hygiene-baseline.jsonjson
{
"timestamp": "2026-02-14T23:00:00Z",
"stack": ["node"],
"scores": {
"dependencies": { "status": "healthy", "vulns": 0, "outdated": 3, "unused": 0 },
"git": { "status": "healthy", "stale_branches": 0, "large_files": 0 },
"ci": { "status": "warning", "unpinned_actions": 2, "permission_issues": 0 },
"quality": { "status": "healthy", "todos": 5, "skipped_tests": 0, "lint_clean": true },
"docs": { "status": "warning", "readme_stale_days": 45, "broken_links": 1 },
"config": { "status": "healthy", "strict_ts": true, "formatter": true, "linter": true },
"security": { "status": "healthy", "tracked_env": 0, "hardcoded_secrets": 0 },
"metadata": { "status": "healthy", "complete": true }
},
"overall": "7/10"
}On subsequent runs, compare with baseline and flag regressions:
text
📉 Dependencies: 0 → 3 vulnerabilities (regression since last check)
📈 Quality: 15 → 5 TODOs (improvement!)
→ CI: unchanged — 2 unpinned actions remainWhen the user approves the report, offer to update the baseline.
每次运行后保存基线,以检测随时间的代码漂移。将基线存储在:
.pi/hygiene-baseline.jsonjson
{
"timestamp": "2026-02-14T23:00:00Z",
"stack": ["node"],
"scores": {
"dependencies": { "status": "healthy", "vulns": 0, "outdated": 3, "unused": 0 },
"git": { "status": "healthy", "stale_branches": 0, "large_files": 0 },
"ci": { "status": "warning", "unpinned_actions": 2, "permission_issues": 0 },
"quality": { "status": "healthy", "todos": 5, "skipped_tests": 0, "lint_clean": true },
"docs": { "status": "warning", "readme_stale_days": 45, "broken_links": 1 },
"config": { "status": "healthy", "strict_ts": true, "formatter": true, "linter": true },
"security": { "status": "healthy", "tracked_env": 0, "hardcoded_secrets": 0 },
"metadata": { "status": "healthy", "complete": true }
},
"overall": "7/10"
}后续运行时,与基线对比并标记退化情况:
text
📉 依赖项:0 → 3个漏洞(自上次检查后出现退化)
📈 代码质量:15 → 5个TODO项(有所改善!)
→ CI:无变化 — 仍有2个未固定版本的Actions当用户确认报告后,可提供更新基线的选项。
Report Format
报告格式
Present the final report as a health scorecard:
markdown
undefined最终报告以健康评分卡形式呈现:
markdown
undefinedRepo Health: <project-name>
仓库健康状态: <项目名称>
Score: 7/10 — GOOD
评分: 7/10 — 良好
Stack: Node.js + TypeScript
技术栈: Node.js + TypeScript
Last check: 2026-01-15 (30 days ago) | Baseline: 6/10 📈
上次检查: 2026-01-15(30天前) | 基线评分: 6/10 📈
🔴 Fix Now (2)
🔴 立即修复(2项)
| # | Category | Issue | Fix |
|---|---|---|---|
| S1 | Security | | |
| D1 | Deps | 2 high-severity npm audit findings | |
| 编号 | 分类 | 问题 | 修复方案 |
|---|---|---|---|
| S1 | 安全 | | |
| D1 | 依赖项 | npm audit发现2个高危漏洞 | |
🟡 Fix Soon (4)
🟡 尽快修复(4项)
| # | Category | Issue | Fix |
|---|---|---|---|
| D2 | Deps | 8 outdated packages (2 major) | |
| C2 | CI | 3 actions not pinned by SHA | Pin to commit SHA |
| F2 | Docs | README 45 days behind source | Review and update |
| Q3 | Quality | 2 skipped tests | Fix or remove |
| 编号 | 分类 | 问题 | 修复方案 |
|---|---|---|---|
| D2 | 依赖项 | 8个过时包(2个大版本更新) | 运行 |
| C2 | CI/CD | 3个Actions未通过SHA固定版本 | 固定到提交SHA |
| F2 | 文档 | README比源码晚更新45天 | 审查并更新 |
| Q3 | 代码质量 | 2个被跳过的测试用例 | 修复或删除 |
🟢 Healthy (12)
🟢 状态健康(12项)
- ✅ Dependencies: no unused, no phantom, lockfile fresh
- ✅ Git: clean tree, no stale branches, no large files
- ✅ Code: lint clean, build passes, tests pass, strict TS
- ✅ Config: EditorConfig, Prettier, ESLint all configured
- ✅ Security: no tracked secrets, .env.example present
- ✅ Metadata: all fields present, license matches
- ✅ 依赖项:无未使用依赖、无幽灵依赖、锁文件新鲜
- ✅ Git:工作树干净、无stale分支、无大文件
- ✅ 代码:代码检查通过、构建成功、测试通过、TypeScript严格模式已启用
- ✅ 配置:已配置EditorConfig、Prettier、ESLint
- ✅ 安全:无被追踪的密钥、已存在.env.example
- ✅ 元数据:所有字段完整、许可证信息一致
📊 Trends (vs. baseline 2026-01-15)
📊 趋势对比(与2026-01-15基线对比)
| Category | Then | Now | Trend |
|---|---|---|---|
| Vulnerabilities | 0 | 2 | 📉 |
| Outdated deps | 5 | 8 | 📉 |
| TODOs | 15 | 8 | 📈 |
| Skipped tests | 0 | 2 | 📉 |
| 分类 | 上次 | 当前 | 趋势 |
|---|---|---|---|
| 漏洞数量 | 0 | 2 | 📉 |
| 过时依赖数量 | 5 | 8 | 📉 |
| TODO数量 | 15 | 8 | 📈 |
| 被跳过的测试数量 | 0 | 2 | 📉 |
Recommendations
建议
- Immediate: Fix the 2 security/vulnerability items above
- This week: Pin CI actions and update stale README
- Ongoing: Address skipped tests and outdated deps in next sprint
Use your project's task tracking to schedule these items.
---- 立即处理:修复上述2个安全/漏洞问题
- 本周内:固定CI Actions版本并更新过时的README
- 持续跟进:在下一个迭代中处理被跳过的测试和过时依赖
使用项目的任务跟踪系统安排这些事项。
---Scoring
评分规则
Calculate the score from check results:
| Result | Points deducted |
|---|---|
| Each 🔴 Fix Now | −1.5 |
| Each 🟡 Fix Soon | −0.5 |
| ℹ️ Info | 0 |
Start at 10, apply deductions, floor at 0. Round to nearest integer.
| Score | Label |
|---|---|
| 9–10 | 🟢 EXCELLENT |
| 7–8 | 🟢 GOOD |
| 5–6 | 🟡 FAIR |
| 3–4 | 🟠 NEEDS WORK |
| 0–2 | 🔴 POOR |
根据检查结果计算评分:
| 结果 | 扣分 |
|---|---|
| 每个🔴 立即修复项 | −1.5 |
| 每个🟡 尽快修复项 | −0.5 |
| ℹ️ 信息提示项 | 0 |
初始分为10分,应用扣分后,最低为0分。结果四舍五入到最近整数。
| 评分 | 标签 |
|---|---|
| 9–10 | 🟢 优秀 |
| 7–8 | 🟢 良好 |
| 5–6 | 🟡 一般 |
| 3–4 | 🟠 需要改进 |
| 0–2 | 🔴 较差 |
Auto-Fix Offers
自动修复建议
After presenting the report, offer to fix issues that are safe and mechanical.
Always present what will be done and get confirmation before executing.
呈现报告后,可提供安全且机械性的问题修复选项。在执行前必须明确告知用户将执行的操作并获得确认。
Safe to offer (low risk, reversible)
可安全提供的修复(低风险、可回滚)
- Delete merged local branches ()
git branch -d - Run (compatible fixes only, not
npm audit fix)--force - Run /
npm dedupego mod tidy - Add missing patterns
.gitignore - Add from template
.editorconfig - Remove from source files
console.log - Create from
.env.example(with values replaced by.env)<REPLACE_ME> - Add missing fields (description, repository, keywords)
package.json - Create
.github/FUNDING.yml
- 删除已合并的本地分支()
git branch -d - 运行(仅应用兼容修复,不使用
npm audit fix)--force - 运行/
npm dedupego mod tidy - 添加缺失的规则
.gitignore - 从模板添加
.editorconfig - 移除源码中的
console.log - 从生成
.env(将值替换为.env.example)<REPLACE_ME> - 添加缺失的字段(描述、仓库、关键词)
package.json - 创建
.github/FUNDING.yml
Offer with warning (confirm carefully)
需谨慎提供的修复(需仔细确认)
- Delete merged remote branches ()
git push origin --delete - Run (may have breaking changes)
npm audit fix --force - Major dependency upgrades
- Enable TypeScript strict mode (may produce many errors)
- Update CI action pinning (must verify correct SHAs)
- 删除已合并的远程分支()
git push origin --delete - 运行(可能存在破坏性变更)
npm audit fix --force - 大版本依赖升级
- 启用TypeScript严格模式(可能产生大量错误)
- 更新CI Action版本固定(必须验证SHA正确性)
Never auto-fix (explain, let user decide)
禁止自动修复(需说明情况,由用户决定)
- Removing tracked files (may need secret rotation)
.env - Rewriting git history (BFG / filter-repo)
- Changing license files
- Modifying CI permissions model
- Removing hardcoded secrets (need to determine replacement strategy)
- 移除被追踪的文件(可能需要轮换密钥)
.env - 重写Git历史(BFG / filter-repo)
- 修改许可证文件
- 修改CI权限模型
- 移除硬编码密钥(需确定替换策略)
Tips
小贴士
- Run early, run often. A monthly cadence catches drift before it compounds.
- Don't try to fix everything at once. Focus on 🔴 items first, batch 🟡 items into a maintenance sprint.
- Baseline tracking is your friend. Even if the score isn't perfect, trending upward means you're winning.
- Pair with pre-release. Run for ongoing health,
repo-hygienewhen you're ready to ship. They complement each other — hygiene keeps the baseline high so pre-release has fewer surprises.pre-release - New repos start clean. Run this right after to establish a perfect baseline. It's easier to maintain 10/10 than to recover from 4/10.
git init
- 尽早运行、定期运行。每月一次的检查可在问题恶化前及时发现代码漂移。
- 不要试图一次性修复所有问题。优先处理🔴 项,将🟡 项批量安排到维护迭代中。
- 基线跟踪很重要。即使评分不完美,只要呈上升趋势就说明在进步。
- 与pre-release技能配合使用。使用进行日常健康维护,使用
repo-hygiene进行发布前检查。二者互补——日常维护可保持基线水平,让预发布检查更少出现意外。pre-release - 新仓库从干净状态开始。在后立即运行此检查,建立完美基线。维持10分比从4分恢复更容易。
git init