1实现原理 · 为什么它能做到
环境修复是『证据驱动』而非『重装一切』:先按固定顺序读 AGENTS.md/CLAUDE.md/ONBOARDING/README/manifest/CI,用只读清单脚本推断真实技术栈,再最小修复。
Use the bundled scripts/check_env.py against the repository root when a Python 3.10+ runner is already available. It detects the declared ecosystem and checks only the relevant toolchain; it does not install dependencies or read secret values.
check_env.py 的探测逻辑是从显式锁文件/清单(uv.lock、package-lock.json、go.mod 等)推断包管理器与运行时,然后跑只读命令保留退出码与 stdout/stderr。
def detect_toolchains(repo: Path) -> list[ToolRequirement]: """Infer package managers and runtimes from explicit manifests/lockfiles."""
『最少机制』排序 + hook 门禁:日常启动同步归 AGENTS.md/CLAUDE.md 或自然语言指令,只有『必须在首个 prompt 前发生』且宿主已验证时才装 SessionStart hook,且必须先 dry-run 预览。
Prefer, in order: direct Agent instruction → project instruction → explicit command → lifecycle hook. A hook is not a more professional version of a sentence.
init_session_start_hook.py 是受管且幂等的 hook 安装器:只加一个带 [auto-repo-setup] 标记的 SessionStart 条目(matcher startup + echo 引导语),校验 guide 路径、保留无关设置、原子写、可 --remove。
The bundled initializer is Claude Code-specific and installs only a lightweight startup context nudge. It preserves unrelated settings, adds matcher startup, validates the guide path, writes atomically, and is idempotent.
Git 流程是『规则门禁 + 状态解释』而非自动操作:clean 才 ff-only pull;有本地改动或历史分叉时禁止自动 stash/merge/rebase/force,改为解释状态。
If the working tree is clean, run git pull --ff-only.
历史敏感信息清理只做只读候选扫描,修复动作交给人工:sanitize_history.sh 自述『只辅助检查』,SKILL.md 要求扫描结果当候选、绝不未经批准执行改写命令。
# 注意:此脚本只辅助检查,最终修复(orphan branch / BFG)需要人工确认后执行。
2核心能力
3外部依赖
| 类型 | 依赖 |
|---|---|
| cli | git |
| cli | python3 / uv |
| cli | sh/bash |
4风险提醒 风险提醒:蓝色 · 知晓即可
- 授权边界依赖模型判断 — 『authority implied by the user's request』由 agent 自行推断,若宿主会话权限宽且模型把『sync the remote』理解成可 push,仍可能执行到超出用户意图的 git 动作;SKILL.md 的门禁是 prompt 级而非执行级约束。
- hook 安装会改变用户日常行为 — SessionStart 条目一旦装上,每次启动都 echo 引导语并可能触发项目指令读取;虽有幂等与 --remove,但『行为变化』本身需要用户知情(dry-run 缓解)。
- sanitize_history 的启发式模式有限 — sk- 前缀等正则匹配会漏报非标准格式密钥、误报普通文本;SKILL.md 也承认绿色扫描器不能替代语义复核。
- 纯 prompt 技能共性 — 一切修复动作经宿主执行;本 skill 不实现沙箱/权限,行为边界靠 SKILL.md 文本纪律与宿主约束共同保证。
5第二遍独立确认
- [ok] check_env.py 只读且不碰 secret — docstring 含『reads secret values』否定句 + 代码仅 git rev-parse/which/shutil.which 探测 + token 扫描零命中。
- [ok] init_session_start_hook.py 行为与 SKILL.md 描述一致(幂等/保留无关设置/原子写) — 脚本 load_settings 校验 JSON 结构并保留 hooks 其余键;update_settings/atomic_write 存在;SKILL.md 原文含『preserves unrelated settings … writes atomically, and is idempotent』同义描述。
- [ok] sanitize_history.sh 永不改写历史 — 脚本头注释『此脚本只辅助检查,最终修复(orphan branch / BFG)需要人工确认后执行』;修复建议仅 echo 输出。
- [ok] Git 门禁(ff-only/不自动 stash/显式批准)有源码依据 — SKILL.md Workflow B 逐条原文存在;Operating principle 4『Never auto-stash, merge, rebase, force, discard, or overwrite local changes…』存在。
- [ok] 无网络外发声明 — scripts/ 三文件 token 扫描仅命中 BFG 文档 URL(输出文案),无任何 fetch/request/curl 调用点。
- [ok] 外部依赖清单(git/python/uv/sh)真实存在 — git:check_env run_cmd 数组含 git;python/uv:SKILL.md 命令与脚本 shebang;sh:sanitize_history.sh shebang。
- [ok] 功能声明 vs 夸大检查 — description 承诺的『Diagnose, repair, and standardize repository setup and safe Git workflows』全部由路由表+脚本+门禁兑现;反例扫描未见越界承诺(无自动破坏性操作、无网络工具)。
- [ok] 元数据(license/stars/commit) — 仓库根 LICENSE 为 MIT (c) 2025 daymade;GitHub API stars=1385、pushed_at=2026-09-09T12:33:29Z;本地 HEAD==pin d5c4678cb5d4fd6acc9c922690df035dbd33d247。
6结论
f95bf84548251fa7…d5c4678cb5