skills/tidy-repo/SKILL.md
Audit repository structure in one pass — detect misplaced files, naming inconsistencies, empty directories, and stale artifacts; produce a prioritized tidy report; optionally apply safe, reversible changes.
npx skillsauth add nesnilnehc/ai-cortex tidy-repoInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
在单次运行中,扫描仓库(或指定范围)的目录结构,识别结构性问题——错放文件、命名不一致、空目录、过期制品、重复条目——并输出一份带优先级的整理报告,指导人工或自动清理。在 apply-safe 模式下,可直接执行安全、可逆的操作。
治理目标:生成一份仓库整理报告,其中 (1) 以标准格式列出所有结构问题及建议操作,(2) 按影响和代价排序,给出具体的清理步骤,(3) 可选地在 apply-safe 模式下执行并记录操作日志。
成功标准(必须满足所有要求):
.git、node_modules、.venv 等)report-only 模式不修改任何文件;apply-safe 仅执行可逆操作验收测试:团队是否可以仅凭此报告的前 5 项行动,让仓库结构显著改善?若否,减少歧义并强化优先级。
本技能负责:
apply-safe 模式下执行移动、删除空目录等可逆操作,并记录日志本技能不负责:
review-codebaseassess-docsalign-planningcommit-work转交点:报告交付后,可将提交操作交给 commit-work;若发现文档规范问题,交给 assess-docs;若发现架构问题,交给 review-codebase。
按 specs/artifact-contract.md §8 Runtime Norms Resolution Protocol 的 §8.2 / §8.3 / §8.5 实现:读项目规范若声明了 repo-tidy artifact_type 的 path_pattern,则使用项目值;否则 fall through 到技能默认(docs/calibration/repo-tidy.md)。本技能为固定路径治理产出,只用 path_pattern 覆盖机制;整理操作本身会尊重项目声明的 artifact path_pattern(移动文件到项目规定的位置而非 AI Cortex 默认)。
report-only,不修改任何文件.git、node_modules、.venv、dist、build、__pycache__、.DS_Store 等目的:确保项目已建立文档规范,以便准确检测命名和路径问题
检查:
docs/ARTIFACT_NORMS.md✗ 找不到文档规范
tidy-repo 需要项目先建立文档规范来准确检测文件位置和命名问题。
请先运行:
/discover-docs-norms
此命令将:
- 扫描现有 docs/ 结构
- 推导出项目的命名和路径约定
- 生成 docs/ARTIFACT_NORMS.md
然后重新运行 tidy-repo。
docs/ARTIFACT_NORMS.md 解析命名规则和目录结构期望对每个条目按以下类别检测:
| 类别 | 检测逻辑 |
| :--- | :--- |
| misplaced | 文件所在目录与其类型/内容不符(如 .md 在 src/,.py 在 docs/) |
| naming | 文件或目录名违反项目约定(大小写、分隔符、前缀/后缀不一致) |
| empty-dir | 目录下无任何有效文件(仅含 .gitkeep 除外) |
| dead-artifact | 明显废弃的文件(扩展名为 .bak、.tmp、.orig;名称含 DEPRECATED、OLD、UNUSED;超过 180 天未修改且无引用) |
| duplicate | 文件名或路径高度相似,疑似重复(如 util.py 与 utils.py 在同目录) |
| structure | 顶层出现非预期目录,或缺少约定的标准目录(如 docs/、src/) |
| root-categorization | docs/ 根目录中的文件应该分类到子目录(不应有除索引、治理文件外的内容) |
| naming/timestamp-misuse | 文件名中包含不必要或格式错误的时间戳(仅对不允许时间戳的类型) |
Root-Categorization 检测细节:
docs/ARTIFACT_NORMS.md 读取允许的根目录文件列表(索引文件、治理文件)docs/ 根目录的所有 .md 文件.md 文件:
root-categorization,建议移至该目录,严重性:suggestion(信息级别)docs/goals.md → 推断类型为 goals → 查询规范 → 建议移至 docs/goals/goals.mdTimestamp-Misuse 检测细节(新增):
docs/ARTIFACT_NORMS.md 读取时间戳政策.md 文件:
YYYY-MM-DD 前缀naming/timestamp-misuse,建议移除前缀naming/timestamp-missing(可选)2026/03/15)→ 建议正确格式:YYYY-MM-DDdocs/requirements-planning/2026-03-15-api-requirements.md → 推断类型为 requirements → 查询规范 → 建议重命名为 api-requirements.md每个发现必须遵循标准格式:
| 字段 | 内容 |
| :--- | :--- |
| 位置 | path/to/file-or-dir |
| 类别 | misplaced | naming | empty-dir | dead-artifact | duplicate | structure | root-categorization | naming/timestamp-misuse |
| 严重性 | critical | major | minor | suggestion |
| 标题 | 简短问题摘要 |
| 描述 | 具体说明哪里不对 |
| 建议 | 具体操作(如"移至 X"、"重命名为 Y"、"删除空目录"、"确认是否废弃后删除") |
汇总:扫描文件总数、目录总数、各类别发现数量、各严重性发现数量。
对每个发现评估:
排序原则:优先处理高影响、低代价的问题(快速胜利);其次为高影响、高代价(需规划);最后为低影响问题(可选)。
输出最小可操作步骤集:
每步包含:
move | rename | delete-empty-dir | archive | review-manually)apply-safe 模式自动执行仅在用户明确传入 apply-safe 模式时激活:
git mv 优先)写入路径(按项目规范或默认 docs/calibration/repo-tidy.md)。报告前置事项:
artifact_type: repo-tidy
created_by: tidy-repo
lifecycle: living
created_at: YYYY-MM-DD
report-only(默认)| apply-safe---
artifact_type: repo-tidy
created_by: tidy-repo
lifecycle: living
created_at: YYYY-MM-DD
---
# Repository Tidy Report
**Date:** YYYY-MM-DD
**Scope:** /path/to/root (filtered: src/)
**Mode:** report-only | apply-safe
**Summary:** N files, M dirs scanned; K findings (critical: X, major: Y, minor: Z, suggestion: W)
## Findings
| Location | Category | Severity | Title | Description | Suggestion |
| :--- | :--- | :--- | :--- | :--- | :--- |
| src/utils.bak | dead-artifact | major | Backup file in source | .bak file committed to source tree | Remove or archive to .archive/ |
(If no findings: "No structural issues found.")
## Cleanup Plan
### Quick Wins (high impact, low effort)
1. **Path:** src/utils.bak
**Action:** delete
**Why now:** Dead artifact pollutes source tree
**Done condition:** File removed; no references in codebase
**Auto-apply:** yes
### Plan Next Sprint (high impact, high effort)
...
### Optional / Low Priority
...
## Apply Log (apply-safe mode only)
| Action | Path | Result |
| :--- | :--- | :--- |
| delete-empty-dir | tmp/ | success |
| move | docs/OLD-arch.md → .archive/OLD-arch.md | success |
| skipped (manual) | src/legacy/ | non-empty directory — review manually |
## Machine-Readable Summary
scope: "."
mode: "report-only"
filesScanned: 142
dirsScanned: 28
findings:
total: 7
bySeverity: { critical: 0, major: 3, minor: 2, suggestion: 2 }
byCategory: { misplaced: 1, naming: 2, empty-dir: 1, dead-artifact: 2, duplicate: 1 }
topActions:
- { path: "src/utils.bak", action: "delete", impact: "high", effort: "small" }
report-only 模式绝不修改任何文件或目录apply-safe 模式绝不删除有内容的目录;所有危险操作标记为"需人工处理"不要做(其他技能处理):
review-codebaseassess-docsalign-planningcommit-work何时停止并交接:
assess-docscommit-workreview-codebase团队是否可以仅凭报告前 5 项行动,让仓库结构显著改善?
若否:减少歧义,强化优先级和具体性。若是:报告已完成。
src/auth.py.bak,7 个月未修改src/auth.py.bak,类别 dead-artifact,严重性 major,标题"源码目录中的备份文件",描述".bak 文件被提交至源码树中",建议"删除或移至 .archive/"apply-safe 可自动执行tmp/cache/(无任何文件)empty-dir,严重性 minor,建议"删除空目录,或添加 .gitkeep 若有意保留"apply-safe 模式:自动删除src/ 下同时存在 UserService.py(PascalCase)和 auth_service.py(snake_case)major,建议"统一命名约定;参考项目现有主导风格决定重命名方向"已执行:delete-empty-dir tmp/cache/ ✓
已执行:move docs/OLD-arch.md → .archive/ ✓
已跳过:src/legacy/(非空目录,需人工处理)
本技能产出 Tidy Report:
| 元素 | 格式 | 必填字段 | 路径模式 | | :--- | :--- | :--- | :--- | | 报告主体 | Markdown | front-matter;章节:摘要 / 错放文件 / 命名违规 / 空目录 / 过期/死文件 / 重复 / 优先清单 | docs/calibration/repo-tidy.md | | 发现条目 | 列表项 | category / path / evidence / severity / suggested_action(move/rename/delete/archive)/ effort_estimate | 各分类章节 | | 优先清单 | 表格 | rank / action / target_path / risk_level / safe_to_auto_apply(bool) | 「优先清单」节 |
development
Generate an LLM agent test suite (golden cases, mock-LLM unit tests, evaluator harness) from an agent implementation and its agent-test contract. Use when an agent has no tests, or a contract exists but the test code is missing.
development
After code changes, auto-detect the project's build system and local deployment method for a given directory, then build the project and restart its locally-deployed environment (Docker Compose / systemd / process manager). Never assumes — asks only when detection is ambiguous. Caches detected commands per project in .cortex/redeploy-local.yaml; re-invocations on the same project skip re-scanning until signal files change, the cache expires (30 days), or the skill version bumps.
tools
Publish a NATS message conforming to a cross-team contract, using NATS MCP tools. Authors the contract on first use if missing. Reads project-level cache (.cortex/nats.yaml) to avoid re-prompting basics across sessions.
tools
Drain pending NATS messages from a producer contract via NATS MCP tools (default batch / drain-style). Applies Tolerant Reader semantics and per-message ack/nak/term, returning aggregated stats. Reads project-level cache (.cortex/nats.yaml) to avoid re-prompting.