codebase-pattern-analyzer
它能做什么
这项技能指导智能体阅读参考代码库,并描述其中可复用的架构。适合希望理解或复制某个项目结构和约定的开发者。
适用场景
- ✓当你需要在复制一个大型代码库之前,先了解它的组织方式的时候。
- ✓当你想从参考项目中提取某个特定模式,例如服务层或 API 代理的时候。
- ✓当你开始一个新项目,并且希望遵循现有项目的约定的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/codebase-pattern-analyzer/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请研究这个参考项目,描述它的组件、服务和 API 模式,以便我构建一个类似的应用。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体梳理目录结构,并根据常见名称和内容,把每个文件夹归类为组件、服务、配置、样式、工具和 API 层等角色。然后它阅读每个角色的文件,用通俗且可复用的语言描述模式。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Codebase Pattern Analyzer
Systematically analyze a reference codebase and extract reusable architectural patterns into structured descriptions. These descriptions become the raw material for new skills (via the skill-template-generator skill).
When to Use
- You need to understand how a large codebase is structured before replicating it
- You want to extract a specific pattern (component architecture, service layer, API proxy, etc.) from a reference project
- You are bootstrapping a new project that should follow the conventions of an existing one
Step 1: Map the Directory Structure
Read the top-level directory and identify the major code zones:
list_dir <project_root>
list_dir <project_root>/src
Classify each directory into one of these roles:
| Role | Typical Dirs | What to Look For |
|---|---|---|
| Components | src/components/ |
UI classes, base class inheritance, DOM manipulation |
| Services | src/services/ |
Data fetching, API calls, circuit breakers, caching |
| Config | src/config/ |
Constants, panel definitions, API endpoints, feature flags |
| Styles | src/styles/ |
CSS custom properties, theme variables, grid layout |
| Utils | src/utils/ |
Helper functions, formatting, DOM utilities |
| API Layer | api/, server/ |
Serverless functions, route handlers, CORS, proxy logic |
| Entry Point | src/main.ts |
Bootstrap, panel instantiation, scheduler setup |
Step 2: Identify the Component Pattern
Find the base component class (usually the most imported file in components/):
read_file <project_root>/src/components/Panel.ts
Extract these structural elements:
- Constructor options interface — what config each component accepts (id, title, className, etc.)
- DOM structure — how the element tree is built (header, content area, resize handles)
- Lifecycle methods — constructor, destroy, show/hide, refresh
- State management — loading/error/content states, fetching guards
- Data binding — how data flows from service → render → DOM
Record the pattern as:
COMPONENT PATTERN:
Base class: [name]
Options: [list of constructor params]
DOM tree: [element hierarchy]
States: [loading, error, content]
Lifecycle: [init → fetch → render → destroy]
Key methods: [getElement, showLoading, showError, setContent, refresh, destroy]
Step 3: Identify the Service Layer Pattern
Examine 2-3 service files to find the common structure:
read_file <project_root>/src/services/news.ts
read_file <project_root>/src/services/stock-market.ts
Look for:
- Circuit breaker / resilience — retry logic, cooldown, cached fallback
- Interface definitions — typed data shapes returned by each service
- Fetch pattern — how HTTP calls are made (direct fetch, proxy, batching)
- Caching strategy — TTLs, stale-while-revalidate, in-memory cache
- Error handling — what happens on failure, default return values
Record as:
SERVICE PATTERN:
Resilience: [circuit breaker with N failures → cooldown]
Cache: [in-memory, TTL=Xms]
Fetch: [browser fetch → /api/... proxy → external API]
Error: [catch → recordFailure → return default]
Exports: [async functions, not class instances]
Step 4: Identify the API Proxy Pattern
Read the server-side proxy layer:
list_dir <project_root>/api/
read_file <project_root>/api/_cors.js
read_file <project_root>/api/stocks.ts # or similar endpoint
Extract:
- File-per-endpoint structure — one file per API domain
- CORS handling — origin allowlist, preflight response
- API key isolation —
process.env.*usage, never exposed to frontend - Cache headers —
Cache-Control,s-maxage,stale-while-revalidate - Error wrapping — structured JSON errors, never raw upstream responses
- Input validation — query parameter checks before upstream call
Step 5: Identify the Styling System
read_file <project_root>/src/styles/main.css # first 100 lines for CSS variables
Extract:
- CSS custom properties — color tokens, font stacks, spacing
- Theme structure — dark/light mode switch mechanism
- Grid layout —
grid-template-columns,auto-fill,minmax()values - Component styles — panel base styles, header, content, scrollbar
- Semantic colors — positive/negative, severity levels, status indicators
- Typography — font family, sizes, letter-spacing, text-tr
常见问题
智能体如何给文件夹分类?
它会根据常见名称和内容,为每个文件夹指定角色,例如组件、服务或 API 层。
输出是什么?
技能会生成结构化的模式说明,之后可以整理成独立的技能。
它会修改参考项目吗?
不会,这项技能是一种分析方法,它阅读代码库来描述它,而不是编辑它。
详情
作者的原始描述
Analyze a reference codebase to discover and extract reusable architectural patterns. Produces structured pattern descriptions that can be turned into standalone skills. This is a meta-skill that bootstraps the skill evolution chain.
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #13039
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …
同一仓库的更多技能
agentpilot
7.8k帮你的智能体准备任务并运行 AgentPilot 循环,逐步改进项目:循环会提出修改、测试修改并为其打分。
openspace
7.8k帮你的智能体设置 OpenSpace,这是一个用于存储和获取智能体技能的工具,并通过 MCP 将其连接到你的 AI 应用。
rsi-arena
7.8k帮你的智能体设置并运行标准 AI 基准测试,例如 AIME 和 Terminal-Bench,用来比较不同的改进方法。
experiment-guide
7.8k帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。