Git 卫生巡检:只读扫描已合并/过期分支、大文件、未跟踪文件与未提交修改,输出体检报告与清理建议,不自动删除任何东西。
安装
# GitHub 源码(首次需按提示配置 allowBuilds 构建授权后重试)
dsh plugin --profile web add github:lucky8197/dsh-git-hygiene
装任何插件都等于在你的机器上跑第三方代码,权限和你本人一样大——能读你的文件、用你的凭据、访问网络,工具审批管不到它。GitHub 来源的插件还会在安装时执行构建脚本。请只安装可信来源,并尽量锁定 commit(github:owner/repo#sha)。
README
Git Hygiene Checker for DeepSeek Harness. A read-only DSH plugin that inspects a repository's hygiene: merged-but-not-deleted branches, stale branches with no commits for months, oversized tracked files, untracked files, and uncommitted work — then outputs a health report with cleanup suggestions. It never deletes or modifies anything automatically. Install with:
dsh plugin --profile web add "github:lucky8197/dsh-git-hygiene#main".
仓库用久了会"长胖":功能分支合并后没人删、几个月不动的老分支堆积、不小心提交了
几十 MB 的二进制、未跟踪文件散落一地。dsh-git-hygiene 用只读 git 命令给仓库
做一次"体检",把这些问题量化成带清理建议的报告。
特性
| 维度 | 说明 | 发现类型 | 严重度 |
|---|---|---|---|
| 已合并分支 | 已合并到当前分支但未删除的分支(git branch --merged) |
merged_branch |
medium |
| 过期分支 | 超过 N 天(默认 90)无提交的分支(for-each-ref committerdate) |
stale_branch |
low |
| 大文件 | 跟踪文件超过阈值(默认 5 MB),提示用 LFS/filter-repo 处理 | large_file |
low |
| 未跟踪文件 | git status --porcelain 的 ?? 条目 |
untracked |
low |
| 未提交修改 | 工作区 dirty 状态(M/A/D 等) |
dirty_worktree |
low |
快速安装
dsh plugin --profile web add "github:lucky8197/dsh-git-hygiene#main"
工具用法
git_hygiene
参数:
cwd?: string 仓库目录(默认当前会话工作目录)
staleDays?: number 过期分支阈值(天,默认 90)
maxFileBytes?: number 大文件阈值(字节,默认 5MB)
输出:canonical JSON 报告(渲染为分节文本)
canonical JSON
{
"tool": "git_hygiene",
"version": 1,
"cwd": "/path/to/repo",
"repo": { "isRepo": true, "root": "/path/to/repo", "branch": "main",
"head": "abc1234…", "remotes": ["origin"], "sizeBytes": 4211000, "objectCount": 1200 },
"findings": [
{ "severity": "medium", "kind": "merged_branch",
"detail": "2 个分支已合并到当前分支,可以安全删除:feature-a、feature-b",
"evidence": "feature-a, feature-b",
"fix": "对每个已合并分支执行 `git branch -d <branch>`(-d 安全删除,未合并会拒绝)" }
],
"stats": { "findingCount": 1, "byKind": { "merged_branch": 1 } },
"suggestions": [ { "severity": "medium", "text": "…" } ]
}
配置(cordis 配置节)
- insert:
- id: git-hygiene
name: 'dsh-git-hygiene'
config:
staleDays: 90 # 过期分支阈值(天)
maxFileBytes: 5242880 # 大文件阈值(字节)
maxList: 30 # 各清单最大展示条数
安全边界(硬性要求)
- 只执行白名单只读 git 子命令(
src/git.tsWHITELIST 全量枚举:status --porcelain / branch --merged / for-each-ref / ls-files / count-objects -v / remote -v / rev-parse / log -1 / symbolic-ref);白名单外的一律拒绝(含checkout/reset/clean/delete/push); - 不自动删除/修改任何分支或文件——只输出建议,清理动作由用户执行;
- 文件体积用只读
node:fs stat,报告不含任何文件内容; - 非 git 目录返回
isRepo: false,不报错不猜测。
防误报设计
- 当前分支自动从"已合并"清单排除(
*标记剥离); - detached HEAD 正常处理(branch 为空,不崩溃);
- 文件缺失/不可读静默跳过。
工程结构
dsh-git-hygiene/
├── package.json # name=dsh-git-hygiene, main=./lib/index.js, dsh.bundle.patch
├── cordis.patch.yml # - insert: [{ id: git-hygiene, name: 'dsh-git-hygiene' }]
├── scripts/ # setup-dsh-deps / build.sh / build-win.mjs(纯 tsc 构建)
├── src/
│ ├── index.ts # apply(ctx):注册 git_hygiene 工具 + 配置读取
│ ├── audit.ts # 编排:只读 git 命令序列 + 大文件 stat
│ ├── git.ts # 白名单执行器(破坏性命令一律拒绝)
│ ├── scan.ts # git 输出解析 + 严重度/建议/渲染
│ └── types.ts # canonical 类型 + 配置
└── tests/ # node --test(22 用例,真实 git 临时仓库端到端)
开发 / 测试 / 构建
npm install && npm run setup
npm test # node --test(22 用例,含真实 git 建仓)
npm run build:win # Windows 构建;POSIX 用 npm run build
构建产物 lib/ 入库提交(GitHub 源安装免构建)。
License
BSD-3-Clause。见 LICENSE。
链接
同类插件
strukto-ai/mirage#dsh★ 3431
把文件系统与 bash 提供者换成 mirage 虚拟工作区:文件工具与 shell 命令作用于挂载的资源(RAM、S3、Redis、Slack、Gmail、Notion、Postgres)而非宿主磁盘,支持按挂载点设置读/写/执行模式、按命令选择沙箱(进程内 monty、pyodide、quickjs;远程 docker、e2b、daytona),并可在虚拟终端中安装 CLI(git、gh、slack、linear、ntn、gws,或自行注册的程序树)作为命令头词。
hust-open-atom-club/oh-dsh★ 176
社区发行版:TUI、桌面端与 Web UI 统一体验,分层安装、一步到位。
Jayden-X-L/forkprobe★ 65
同一任务并行试跑多个技能,对比结果选出最优。
vlln/plugin-registry★ 39
插件生态基建:浏览器面板管理官方 repository 插件(0 patch)+ make-dsh-plugin 插件开发引导技能。
forrestchang/dsh-multica-runtime★ 33
让 dsh 运行时跑在 Multica 上。
DietCokewithSugar/dsh-user-experience★ 18
帮你发现项目中可能存在的用户体验问题:自动走查 React/TypeScript 源码,定位问题并给出具体优化建议。