Code that stays in spec, not just reviewed after.
代码始终符合规范,而非事后才审查。
A coding-standard enforcer for AI agents working inside a research codebase. It enforces two standards: a steady project framework that stays consistent, and healthy code — clear comments, sensible APIs, thorough modularization.
一个面向 AI 智能体的编码规范执行器,作用于科研代码库。它在 Agent 工作时强制执行两项规范:一套稳定、始终一致的项目框架,以及健康的代码——注释清晰、API 设计合理、模块化完善。
What it does.
能力列表。
- 🏗️Project level: establish a clear, predictable structure and keep it that way.🏗️项目层面,建立一套清晰、可预期的结构并长期保持。
- 🧩Models decoupled from systems, self-contained, fixed method order.🧩模型与系统分离,模型自包含,遵循固定方法顺序。
- ⚙️All experiment params in config files; code only reads config, no hardcoding.⚙️实验参数一律走配置文件,代码只从配置读取,杜绝硬编码。
- 🔁Reproducible: config, data version, code tag bound together, results regenerate.🔁实验可复现:配置、数据版本、代码 tag 三者绑定,结果可重生。
- 🚦Mandatory gates (black / isort / ruff / mypy / pytest) pass before accept.🚦强制质量门(black / isort / ruff / mypy / pytest),变更接受前必须通过。
- 💬Code level: comments explain the thinking, sensible APIs, clean modularization.💬代码层面,注释讲清思路、API 设计合理、模块化完善。
- 🏛️Named architectures & pluggability: timm tiers, OpenMMLab, no
if model=="...".🏛️命名架构加可插拔:timm 分层、OpenMMLab 注册即用,拒绝if model == "..."分支。 - 📦Ships as a package; CI runs style+type checks; small reviews, docs don't drift.📦以可安装包交付,CI 跑风格与类型检查,小步评审、接口文档不漂移。
- 🧠Behavior discipline: think first, keep simple, surgical edits, goal-driven.🧠行为纪律:先想后写、保持简单、外科手术式改动、目标驱动执行。
- 🔧Automaintained
.gitignore: syncs with layout, keeps hand-written rules.🔧自动维护的.gitignore:随目录结构变化同步忽略规则,不破坏手写规则。 - 📂Run artifacts funnel into
.cache/; nothing litters the repo root.📂运行产物收口到.cache/,仓库根不散落缓存文件。 - 🤝Key principle: never deletes/rewrites your code — only moves or renames it.🤝关键原则:Agent 不会随意删除或重写你的代码,只移动、重命名以保持行为不变。
- 📏Every rule is checkable, applied live as work proceeds, not just cited.📏每条规范编码为可检查的规则,随工作实时应用与校验,而非仅引用文档。
Two scenario examples.
两个场景示例。
The agent scaffolds the structure, then writes src/, configs/, and Hydra _target_ per the standard.
Agent 从骨架建结构,再按规范写 src/、configs/、Hydra _target_。
The agent audits drift, then refactors/rename into compliance and re-runs the gates.
Agent 先审计偏离,再重构重命名至合规,重跑校验门确认。
Reference projects.
参考项目。
| Concern | 关注领域 | Basis | 依据 |
|---|---|---|---|
| Project structure & style | 项目结构与写法 | Lightning-Hydra-Template, Hydra, Google Python Style | Lightning-Hydra-Template、Hydra、Google Python Style |
| Model & component design | 模型与组件设计 | PyTorch Lightning Style, timm, OpenMMLab | PyTorch Lightning Style、timm、OpenMMLab |
| Reproducible experiments | 可复现实验 | Hydra, FAIR, SemVer, Git Flow, Meta Research | Hydra、FAIR、SemVer、Git Flow、Meta Research |
| Engineering habits & interfaces | 工程习惯与接口 | Software Engineering at Google, Scientific Python, research-code commenting standard | Software Engineering at Google、Scientific Python、科研代码注释规范 |
| LLM coding discipline | LLM 编码纪律 | Karpathy Skills | Karpathy Skills |
Quick start.
快速开始。
Clone to a stable path (don't develop inside this copy); point the agent at SKILL.md:
克隆到稳定路径(不要在此副本内开发),让 Agent 指向 SKILL.md:
# clone the skill to a stable path# 克隆 skill 到稳定路径 git clone https://github.com/SaltGardenia/research-code-skill.git \ ~/ai-skills/research-code-skill # Claude Code — load the main file as a subagent# Claude Code —— 用 subagent 加载主文件 mkdir -p ~/.claude/agents cat > ~/.claude/agents/research-code-skill.md <<'EOF' --- name: research-code-skill description: 用于以固定结构、统一规范搭建或整理科研(ML/DL)代码库。 --- When invoked, first read `~/ai-skills/research-code-skill/SKILL.md` and follow it as the governing workflow. Read supporting files from `~/ai-skills/research-code-skill/` only when needed. Do not replace this skill with a generic coding response. EOF
Other agents (Kilo, Codex, etc.) keep the full folder: create a subagent / slash command / custom prompt pointing at the main file. Update: cd ~/ai-skills/research-code-skill && git pull.
其他 Agent(Kilo、Codex 等)同样保留完整文件夹,创建指向主文件的 subagent / slash command / 自定义 prompt。更新:cd ~/ai-skills/research-code-skill && git pull。
Run the checker locally: first python -m pip install -r requirements.txt, then python scripts/audit_style.py ., python scripts/sync_gitignore.py ., bash scripts/run_gate.sh.
本地运行检查器:先 python -m pip install -r requirements.txt,再依次运行 python scripts/audit_style.py .、python scripts/sync_gitignore.py .、bash scripts/run_gate.sh。