analyze-project
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAnalyze Project
项目分析
Scan a project and produce or update and — living documentation that any AI agent session can read to instantly understand the project without re-scanning from scratch.
docs/TechStack.mddocs/ProjectStructure.md扫描项目并生成或更新和——这是一种动态文档,任何AI Agent会话都可以通过读取它快速了解项目,无需从头重新扫描。
docs/TechStack.mddocs/ProjectStructure.mdWhen to Use
适用场景
- Starting work on a project for the first time
- Before any feature work when project docs don't exist yet
- Periodically to keep docs current after codebase changes
- After major refactors, dependency upgrades, or service additions
When NOT to use: and exist and no significant structural changes (config files, directories, container configs) have occurred since the last scan.
docs/TechStack.mddocs/ProjectStructure.md- 首次开始项目工作时
- 项目文档尚未存在,即将开展功能开发前
- 代码库变更后定期运行以保持文档最新
- 重大重构、依赖升级或新增服务后
不适用场景:和已存在,且自上次扫描以来未发生重大结构变更(配置文件、目录、容器配置等)。
docs/TechStack.mddocs/ProjectStructure.mdInput
输入
- A project or workspace root (provided by user or detected from workspace)
- 项目或工作区根目录(由用户提供或从工作区自动检测)
Output
输出
- — concise tech stack reference card
docs/TechStack.md - — operational project map
docs/ProjectStructure.md - In monorepos: per-service copies under
[service-path]/docs/
- ——简洁的技术栈参考卡片
docs/TechStack.md - ——可操作的项目结构图
docs/ProjectStructure.md - 单仓库场景:在下生成对应服务的文档副本
[服务路径]/docs/
The Process
操作流程
Step 1: Check Existing Docs
步骤1:检查现有文档
Check if and exist at the project root.
docs/TechStack.mddocs/ProjectStructure.mdIf they exist, read them and extract the YAML frontmatter:
yaml
---
generated-by: analyze-project
date: 2024-03-14T12:00:00Z
commit: abc1234
---If the files exist, hold their contents — you'll compare against fresh scan results later.
检查项目根目录下是否存在和。
docs/TechStack.mddocs/ProjectStructure.md若存在,则读取文件并提取YAML frontmatter内容:
yaml
---
generated-by: analyze-project
date: 2024-03-14T12:00:00Z
commit: abc1234
---若文件已存在,先保留其内容,后续将与新扫描结果进行对比。
Step 2: Staleness Gate
步骤2:时效性检查
Run to get the current commit hash.
git rev-parse --short HEADIf the field in frontmatter differs from HEAD (it usually will — it records the commit at last scan, not the latest), check what actually changed:
commitRun to get committed changes, and to get uncommitted changes (staged, unstaged, and untracked files). Combine both lists.
git diff --name-only <frontmatter-commit>..HEADgit status --shortEvaluate whether the changes are significant for project docs:
- Significant changes (trigger re-scan): new/removed/renamed config files (,
package.json,composer.json,docker-compose.yml,Dockerfile,Makefile, etc.), new/removed top-level directories, changes to*.config.*, CI config changes, README/INSTALL/SETUP changes.devcontainer/ - Insignificant changes (skip re-scan): source code changes within existing directories, test changes, asset changes, documentation changes in subdirectories
Decision:
- Files don't exist → Proceed to scan.
- Files exist, commits match HEAD → Report "Project docs are up to date." and stop.
- Files exist, commits differ, only insignificant changes → Report "Project docs are up to date (no structural changes since last scan)." and stop.
- Files exist, commits differ, significant changes detected → Report which files changed and proceed to scan.
- No commit field in frontmatter → Proceed to scan.
If git is not available, skip this check and always proceed to scan.
执行命令获取当前commit哈希值。
git rev-parse --short HEAD若frontmatter中的字段与HEAD不一致(通常都会不同,因为该字段记录的是上次扫描时的commit,而非最新commit),则检查具体变更内容:
commit执行获取已提交的变更,执行获取未提交的变更(暂存、未暂存和未跟踪文件),合并两个结果列表。
git diff --name-only <frontmatter-commit>..HEADgit status --short评估变更是否会影响项目文档:
- 重大变更(触发重新扫描):新增/删除/重命名配置文件(、
package.json、composer.json、docker-compose.yml、Dockerfile、Makefile等)、新增/删除顶级目录、*.config.*目录变更、CI配置变更、README/INSTALL/SETUP文档变更.devcontainer/ - 非重大变更(跳过重新扫描):现有目录内的源代码变更、测试代码变更、资源文件变更、子目录内的文档变更
决策逻辑:
- 文件不存在 → 继续执行扫描。
- 文件存在,commit与HEAD一致 → 提示“项目文档已处于最新状态。”并终止流程。
- 文件存在,commit与HEAD不一致,但仅存在非重大变更 → 提示“项目文档已处于最新状态(自上次扫描以来未发生结构变更)。”并终止流程。
- 文件存在,commit与HEAD不一致,且检测到重大变更 → 告知用户哪些文件发生变更,然后继续执行扫描。
- frontmatter中无字段 → 继续执行扫描。
commit
若无法使用git,则跳过该检查,直接执行扫描。
Step 3: Ownership Check
步骤3:所有权检查
For each existing file, check the field in YAML frontmatter:
generated-by- present → Skill owns this file. Will update without asking.
generated-by: analyze-project - File exists but no → Manually authored. Ask the user before overwriting:
generated-by: analyze-project
"exists but wasn't generated by this skill. Overwrite it? (yes/no)"docs/TechStack.md
If user declines, skip that file and report findings in chat instead.
对于每个已存在的文件,检查YAML frontmatter中的字段:
generated-by- 存在→ 该文件由本技能维护,将直接更新,无需询问。
generated-by: analyze-project - 文件存在但无→ 为手动编写文档,覆盖前需询问用户:
generated-by: analyze-project
"已存在,但并非由本技能生成。是否覆盖该文件?(是/否)"docs/TechStack.md
若用户拒绝覆盖,则跳过该文件,仅在聊天中告知扫描结果。
Step 4: Scan Root
步骤4:扫描根目录
List the project root directory. Read relevant files found:
Config files (reveal tech stack):
- ,
package.json,composer.json,Cargo.toml,go.mod,pyproject.toml,Gemfile,build.gradle, etc.pom.xml - ,
tsconfig.json,vite.config.*,webpack.config.*, etc.nuxt.config.*
Container and dev environment:
- /
docker-compose.ymldocker-compose.yaml Dockerfile.devcontainer/devcontainer.json
CI/CD:
.github/workflows/*.yml.gitlab-ci.ymlJenkinsfile
Documentation:
README.md- ,
INSTALL.mdSETUP.md
Quality tooling:
Makefile- ,
.eslintrc.*eslint.config.* .prettierrc- ,
phpunit.xml,vitest.config.*,jest.config.*pytest.ini
Start from the root listing. If root has enough config files, that's all you need. If root contains only a single folder (e.g., the repo wraps one project in a subdirectory), treat that folder as the effective root and list it instead. If root is unclear, run a quick glob for config files () limited to a small number of results — the paths reveal where projects and services live (e.g., ). Then read those directories. Avoid full recursive filesystem scans.
**/{*.yml,*.yaml,*.json,*.toml,*.ini,*.md}services/api/package.json列出项目根目录内容,读取找到的相关文件:
配置文件(用于识别技术栈):
- 、
package.json、composer.json、Cargo.toml、go.mod、pyproject.toml、Gemfile、build.gradle等pom.xml - 、
tsconfig.json、vite.config.*、webpack.config.*等nuxt.config.*
容器与开发环境:
- /
docker-compose.ymldocker-compose.yaml Dockerfile.devcontainer/devcontainer.json
CI/CD配置:
.github/workflows/*.yml.gitlab-ci.ymlJenkinsfile
文档:
README.md- 、
INSTALL.mdSETUP.md
质量工具配置:
Makefile- 、
.eslintrc.*eslint.config.* .prettierrc- 、
phpunit.xml、vitest.config.*、jest.config.*pytest.ini
从根目录列表开始扫描。若根目录包含足够的配置文件,则无需进一步扫描。若根目录仅包含单个文件夹(例如仓库将项目嵌套在子目录中),则将该文件夹视为实际根目录并扫描其内容。若根目录不明确,则快速搜索配置文件(),限制返回结果数量——路径会揭示项目和服务的位置(例如)。然后扫描这些目录。避免对文件系统进行全递归扫描。
**/{*.yml,*.yaml,*.json,*.toml,*.ini,*.md}services/api/package.jsonStep 5: Detect Monorepo
步骤5:检测单仓库(Monorepo)
Check for monorepo signals from what was found in Step 4:
- Directories named ,
apps/,services/at rootpackages/ - defining multiple services with build contexts
docker-compose.yml - Workspace config in (
package.jsonfield) orworkspacespnpm-workspace.yaml - Multiple references in different subdirectories
Dockerfile
If monorepo detected, identify service directories and their names.
根据步骤4的结果,检查是否存在单仓库特征:
- 根目录下存在、
apps/、services/目录packages/ - 中定义了多个带有构建上下文的服务
docker-compose.yml - 中的
package.json字段或workspaces中的工作区配置pnpm-workspace.yaml - 不同子目录中存在多个引用
Dockerfile
若检测到单仓库,则识别服务目录及其名称。
Step 6: Scan Services (monorepo only)
步骤6:扫描服务(仅单仓库场景)
For each service directory identified in Step 5, apply the same root-reading approach:
- List the service directory
- Read its config files (package.json, composer.json, Dockerfile, etc.)
- Read its README.md if present
- Note its doc location, dev/lint/test commands
对于步骤5中识别的每个服务目录,应用相同的根目录扫描逻辑:
- 列出服务目录内容
- 读取其配置文件(package.json、composer.json、Dockerfile等)
- 若存在README.md则读取该文件
- 记录其文档位置、开发/ lint/测试命令
Step 7: Write Docs
步骤7:生成文档
Use the templates from .
references/formats.mdSingle project:
- Write with tech stack reference card
docs/TechStack.md - Write with operational project map
docs/ProjectStructure.md - ends with a "See Also" link to
ProjectStructure.mdDatabaseStructure.md
Monorepo:
- Write root with shared stack + per-service summary
docs/TechStack.md - Write root with service table and monorepo-level overview
docs/ProjectStructure.md - For each service, write and
[service-path]/docs/TechStack.md[service-path]/docs/ProjectStructure.md - Create directories if they don't exist
docs/
All files get YAML frontmatter with:
generated-by: analyze-project- current ISO 8601 datetime
date: - current short git commit hash
commit:
Announce the saved paths:
"Project docs updated:
docs/TechStack.md [per-service paths if monorepo] Commit: [hash]"docs/ProjectStructure.md
使用中的模板。
references/formats.md单个项目场景:
- 生成,包含技术栈参考卡片
docs/TechStack.md - 生成,包含可操作的项目结构图
docs/ProjectStructure.md - 末尾需添加指向
ProjectStructure.md的“另请参阅”链接DatabaseStructure.md
单仓库场景:
- 生成根目录下的,包含共享技术栈和各服务的摘要信息
docs/TechStack.md - 生成根目录下的,包含服务列表和单仓库概览
docs/ProjectStructure.md - 为每个服务生成和
[服务路径]/docs/TechStack.md[服务路径]/docs/ProjectStructure.md - 若目录不存在则创建
docs/
所有生成的文件需包含YAML frontmatter,内容如下:
generated-by: analyze-project- 当前ISO 8601格式的时间戳
date: - 当前git短提交哈希值
commit:
向用户告知已保存的文件路径:
"项目文档已更新:
docs/TechStack.md [单仓库场景下的各服务文档路径] 提交哈希:[hash]"docs/ProjectStructure.md
Common Rationalizations
常见误区澄清
| Rationalization | Reality |
|---|---|
| "The README has all this info" | READMEs describe intent and setup steps. TechStack and ProjectStructure describe current reality in a structured, machine-readable format. |
| "I can just read package.json" | One config file gives you one piece. These docs synthesize all signals into two quick-read files. |
| "The project is small, I don't need docs" | Small projects still have a stack, structure, and tooling. Two short files save every future session from re-discovering them. |
| "Docs will get outdated" | The staleness gate and commit tracking exist specifically to prevent this. Run the skill again. |
| 误区 | 实际情况 |
|---|---|
| "README中已包含所有信息" | README描述的是项目意图和安装步骤,而TechStack和ProjectStructure文档以结构化、机器可读的格式描述项目当前的实际状态。 |
| "我直接读package.json就够了" | 单个配置文件只能提供部分信息,这些文档会整合所有信号,生成两个便于快速阅读的文件。 |
| "项目很小,不需要文档" | 小型项目同样有技术栈、结构和工具链,两个简短的文档可以为未来的所有会话节省重新探索的时间。 |
| "文档会过时" | 时效性检查和commit追踪机制正是为了防止这种情况发生,只需再次运行本技能即可。 |
Red Flags
注意事项
- Skipping the staleness check and always rewriting (wastes time, loses manual edits)
- Deep-scanning the filesystem instead of reading root
- Not including YAML frontmatter in output files
- Overwriting manually-authored files without asking
- Missing the monorepo detection step on a multi-service project
- Writing rationale or opinions instead of facts in TechStack.md
- Not creating directory before writing
docs/
- 跳过时效性检查并始终重写文档(浪费时间,丢失手动编辑内容)
- 对文件系统进行深度扫描而非仅读取根目录
- 生成的文件中未包含YAML frontmatter
- 未询问用户就覆盖手动编写的文件
- 在多服务项目中未检测到单仓库
- 在TechStack.md中写入理由或观点而非事实
- 生成文档前未创建目录
docs/
Verification
验证清单
Before finishing, confirm:
- Staleness check performed (or git unavailable noted)
- Ownership check performed for existing files
- Root directory listing read (not deep-scanned)
- Relevant config files read
- written with frontmatter and concise stack listing
docs/TechStack.md - written with frontmatter and operational map
docs/ProjectStructure.md - ends with reference to
ProjectStructure.mdDatabaseStructure.md - If monorepo: services detected and per-service docs written
- All generated files have ,
generated-by, anddatein frontmattercommit - Saved paths announced to user
完成前请确认:
- 已执行时效性检查(或已注明无法使用git)
- 已对现有文件执行所有权检查
- 已读取根目录列表(未进行深度扫描)
- 已读取相关配置文件
- 已生成带有frontmatter和简洁技术栈列表的
docs/TechStack.md - 已生成带有frontmatter和可操作结构图的
docs/ProjectStructure.md - 末尾已添加指向
ProjectStructure.md的引用DatabaseStructure.md - 若为单仓库场景:已检测到服务并生成对应服务的文档
- 所有生成的文件的frontmatter中包含、
generated-by和date字段commit - 已向用户告知已保存的文件路径