read-codebase

阅读棕地项目代码库,智能分析代码结构,递归补充其调用链上所有函数的注释。

Best use case

read-codebase is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

阅读棕地项目代码库,智能分析代码结构,递归补充其调用链上所有函数的注释。

Teams using read-codebase should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/read-codebase/SKILL.md --create-dirs "https://raw.githubusercontent.com/Lionad-Morotar/local-tools/main/local-link/skills/read-codebase/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/read-codebase/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How read-codebase Compares

Feature / Agentread-codebaseStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

阅读棕地项目代码库,智能分析代码结构,递归补充其调用链上所有函数的注释。

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Read Codebase Skill

用于阅读和理解棕地(Brownfield)项目代码库,提供智能代码分析和文档补充能力。

## 模式一(默认执行):函数注释补全

当用户输入包含函数路径或要求补充函数注释时,执行此模式。

### 执行步骤

#### 1. 识别目标函数
- 从用户输入中提取目标函数的文件路径和行号
- 如果没有明确行号,使用 Grep 搜索函数定义
- 读取函数签名和上下文(前后 50 行)
- 如果没有明确行号,则尝试高层次洞见整个文件

#### 2. 递归扫描调用链

**广度优先遍历(BFS)策略:**

```
Level 0: 入口函数(用户指定函数、或默认整个文件、组件、模块)
Level 1: 入口函数体内直接调用的所有函数
Level 2: Level 1 函数调用的所有函数
Level 3+: 继续递归直到叶子节点
```

**扫描范围(按优先级):**

| 优先级 | 类型 | 说明 |
|-------|------|------|
| P0 | 项目内部函数 | 必须补充,核心业务逻辑 |
| P1 | 接口方法 | 组件接口、组件 props 等 |
| P2 | 工具/辅助函数 | 必须补充,提高可读性 |
| P3 | 标准库函数 | 简要说明,不强制 |
| P4 | 第三方库函数 | 简要说明,不强制 |

**扫描技巧:**
- 使用 `Grep` 查找函数定义位置
- 使用 `LSP` 的 `incomingCalls`/`outgoingCalls` 获取调用关系
- 对于接口类型,找到所有实现并分别处理

#### 3. 判断是否需要补充注释

**已有注释的检查:**
- 函数定义前是否有 `//` 开头的注释块
- 注释是否包含功能描述
- 注释是否包含输入/输出示例
- 每一个组件 prop 都要有一行简短的注释,复杂 prop 酌情增加注释量

**无需补充的情况:**
- 已有完整注释(描述 + 示例)
- 私有函数(小写开头)且逻辑极简单(<5 行)
- Getter/Setter 等样板代码
- 明显的回调函数(如 `http.HandlerFunc`)

#### 4. 生成注释

**格式规范:**

* TypeScript:JSDoc

```go
// 函数名 一句话功能描述。
//
// 输入示例:
//   - 参数名: 具体值(含类型说明)
//   - 参数名2: map[string]any{"key": "value"}
//
// 输出示例:
//   - 成功: 
//   - 失败: 
func FunctionName(param Type) (Result, error)
```

**输入示例编写原则:**
- 使用真实可运行的示例值
- 复杂结构体给出具体字段值
- 接口类型给出常见实现示例
- 如有多种调用方式,补充多个示例

**输出示例编写原则:**
- 必须覆盖成功和失败场景
- 失败场景给出典型错误类型
- 多返回值场景说明各返回值含义
- 如有副作用(如修改 context),需注明

#### 5. 批量编辑

**编辑顺序:**
1. 从最底层(叶子节点)开始,自下而上
2. 同一层按文件分组,减少上下文切换
3. 优先处理被多个上层函数调用的公共函数
4. 保证组件的每一个 prop 都有一行注释

**编辑技巧:**
- 使用 `Read` 确认当前文件状态
- 使用 `Edit` 精确替换函数定义行
- 编辑后使用 `Read` 验证格式正确

### 输出格式

完成任务后,按以下格式汇报:

```markdown
## 函数注释补全报告

### 调用链分析

```
入口函数: pkg/service/handler.go:45 HandleRequest
├── Level 1
│   ├── pkg/utils/validator.go:23 ValidateInput
│   └── pkg/db/query.go:67 GetUser
│       └── Level 2
│           ├── pkg/db/conn.go:12 OpenConnection
│           └── pkg/cache/redis.go:34 GetCache
└── Level 1
    └── pkg/log/logger.go:89 Infof
```

### 已补充注释的函数

| 文件 | 行号 | 函数名 | 层级 |
|------|------|--------|------|
| pkg/service/handler.go | 45 | HandleRequest | Level 0 |
| pkg/utils/validator.go | 23 | ValidateInput | Level 1 |
| pkg/db/query.go | 67 | GetUser | Level 1 |
| pkg/db/conn.go | 12 | OpenConnection | Level 2 |
| pkg/cache/redis.go | 34 | GetCache | Level 2 |

### 跳过补充的函数

| 文件 | 函数名 | 原因 |
|------|--------|------|
| pkg/log/logger.go | Infof | 标准库风格,已有注释 |

总计:补充 [Z 个组件,][X 个函数,][跳过 Y 个函数]
```

## 最佳实践

### 注释质量检查清单

- [ ] 描述以函数名开头,形成完整句子
- [ ] 输入示例包含具体值,不是类型名
- [ ] 输出示例覆盖成功和失败场景
- [ ] 复杂业务逻辑说明关键决策点
- [ ] 错误返回值说明触发条件

### 性能优化

- 大型项目(>1000 文件)时,限制扫描深度(建议 max 3 层)
- 使用并行 Grep 加速函数定位
- 缓存已分析的函数签名,避免重复读取

### 常见陷阱

1. **循环依赖**: 调用链成环时,标记已访问函数避免无限递归
2. **接口多实现**: 接口方法需找到所有实现分别补充
3. **泛型函数**: Go 泛型函数需保留类型参数示例
4. **内联函数**: 小函数可能被编译器内联,注释价值低

## 工具使用指南

### 推荐工具组合

| 场景 | 工具 | 用法 |
|------|------|------|
| 查找函数定义 | Grep | `pattern: "func FunctionName"` |
| 查找调用关系 | LSP | `operation: outgoingCalls` |
| 读取函数上下文 | Read | `limit: 50, offset: line-10` |
| 批量编辑 | Edit | 精确定位函数定义行 |

### Grep 模式示例

```
# 查找函数定义
func\s+\w+\s*\(.*\)\s*\{?

# 查找方法定义(带接收器)
func\s*\([^)]+\)\s*\w+\s*\(

# 查找接口定义
type\s+\w+\s+interface\s*\{
```

Related Skills

recognize-codebase-branch-flow

7
from Lionad-Morotar/local-tools

识别并记忆项目 git 分支模型

proof-reading

7
from Lionad-Morotar/local-tools

修复语病,使句子更通顺

proof-reading-execute

7
from Lionad-Morotar/local-tools

修复语音输入,然后执行

open-u-dashboard

7
from Lionad-Morotar/local-tools

open understand dashboard for user

sync-template-skill

7
from Lionad-Morotar/local-tools

这是一个技能文件的模板,展示了技能的基本结构和内容组织方式。

talk-humanize

7
from Lionad-Morotar/local-tools

Be direct and informative. No filler, no fluff, but give enough to be useful.

search-web

7
from Lionad-Morotar/local-tools

使用 Evaluator-optimizer 模式进行系统性多轮网络搜索,采用结构化 Ask 流程在搜索前澄清研究目标。基于 YC Office Hours 的提问方法论,确保搜索方向清晰、结果可验证。当用户需要深入调查复杂主题、验证假设或全面收集信息时使用。

save-to-eagle

7
from Lionad-Morotar/local-tools

归档网络内容到 Eagle 素材库。支持:(1) Behance/Pixiv 图片归档,(2) 网页视频录制(页面动画、滚动录制)。使用方式:'归档 [URL]' 归档图片;'录制网页视频 [URL]' 录制页面动画;'滚动录制 [URL]' 自动滚动截图。支持评分如 '归档 [URL], 3/5'。

save-ob-chaos

7
from Lionad-Morotar/local-tools

将对话内容快速存档到 Obsidian Chaos 文件夹。触发词:"存档到 Obsidian"、"保存到 Chaos"、"ob 存档"、"记下这个"、"保存这段内容"、"存到 chaos"。

save-ob-chaos-mermaid

7
from Lionad-Morotar/local-tools

将 Mermaid 图表保存到 Obsidian Chaos 文件夹。触发词:"保存 mermaid 到 chaos"、"mermaid 存档"。

save-ob-chaos-excalidraw

7
from Lionad-Morotar/local-tools

绘制 Excalidraw 图表并存档到 Obsidian Chaos 文件夹。触发词:"画个图存到 Obsidian"、"excalidraw 存档"、"画个流程图保存"、"画图存到 chaos"、"创建图表并存档"、"画架构图到 ob"。

release-project

7
from Lionad-Morotar/local-tools

项目版本发布流程指导,帮助用户完成版本规划、Changelog 管理、版本号升级、Git 标签创建和 npm 首次发布准备。Use when: (1) 用户需要发布新版本 (2) 需要创建版本发布流程 (3) 需要管理版本号和 Changelog (4) 需要自动化版本发布 (5) 需要检查 release 分支同步 (6) 首次 npm 发布准备