关于 code-documenter
Code Documenter 面向编写代码文档、API 规范和开发者指南的任务。它涵盖格式选择、框架识别、示例验证和文档覆盖率汇总。
主要功能
- 01编写代码内文档
- 02制作 API 规范和开发者指南
- 03识别语言与框架
- 04验证文档中的代码示例
- 05汇总文档覆盖率
适用场景
- 01为公开函数和类编写文档
- 02为项目整理 API 规范
- 03创建开发者指南和文档站点
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ farmage/ opencode-skills --skill code-documenter安装后在 Claude Code 中输入/code-documenter确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/api-docs-fastapi-django.mdapi-docs-nestjs-express.mdcoverage-reports.mddocumentation-systems.mdinteractive-api-docs.mdpython-docstrings.mdtypescript-jsdoc.mduser-guides-tutorials.md详细介绍
代码文档编写器
专注于内联文档、API 规范、文档站点和开发者指南的文档专家。
何时使用此技能
适用于涉及代码文档、API 规范或面向开发者的指南的任何任务。有关具体子主题,请参阅下方的参考表。
核心工作流
- 发现 - 询问格式偏好和排除项
- 检测 - 识别语言和框架
- 分析 - 查找缺少文档的代码
- 编写文档 - 应用一致的格式
- 验证 - 测试所有代码示例能否编译/运行:
- Python:对于 doctest 代码块,运行
python -m doctest file.py;对于整个模块的检查,运行pytest --doctest-modules - TypeScript/JavaScript:运行
tsc --noEmit,确认类型化示例可以编译 - OpenAPI:使用
npx @redocly/cli lint openapi.yaml验证规范 - 如果验证失败:修复示例并重新验证,然后再进入报告步骤
- Python:对于 doctest 代码块,运行
- 报告 - 生成覆盖率摘要
快速参考示例
Google 风格的文档字符串(Python)
def fetch_user(user_id: int, active_only: bool = True) -> dict:
"""Fetch a single user record by ID.
Args:
user_id: Unique identifier for the user.
active_only: When True, raise an error for inactive users.
Returns:
A dict containing user fields (id, name, email, created_at).
Raises:
ValueError: If user_id is not a positive integer.
UserNotFoundError: If no matching user exists.
"""
NumPy 风格的文档字符串(Python)
def compute_similarity(vec_a: np.ndarray, vec_b: np.ndarray) -> float:
"""Compute cosine similarity between two vectors.
Parameters
----------
vec_a : np.ndarray
First input vector, shape (n,).
vec_b : np.ndarray
Second input vector, shape (n,).
Returns
-------
float
Cosine similarity in the range [-1, 1].
Raises
------
ValueError
If vectors have different lengths.
"""
JSDoc(TypeScript)
/**
* Fetches a paginated list of products from the catalog.
*
* @param {string} categoryId - The category to filter by.
* @param {number} [page=1] - Page number (1-indexed).
* @param {number} [limit=20] - Maximum items per page.
* @returns {Promise<ProductPage>} Resolves to a page of product records.
* @throws {NotFoundError} If the category does not exist.
*
* @example
* const page = await fetchProducts('electronics', 2, 10);
* console.log(page.items);
*/
async function fetchProducts(
categoryId: string,
page = 1,
limit = 20
): Promise<ProductPage> { ... }
参考指南
根据上下文加载详细指南:
| 主题 | 参考资料 | 加载时机 |
|---|---|---|
| Python 文档字符串 | references/python-docstrings.md | Google、NumPy、Sphinx 风格 |
| TypeScript JSDoc | references/typescript-jsdoc.md | JSDoc 模式、TypeScript |
| FastAPI/Django API | references/api-docs-fastapi-django.md | Python API 文档 |
| NestJS/Express API | references/api-docs-nestjs-express.md | Node.js API 文档 |
| 覆盖率报告 | references/coverage-reports.md | 生成文档报告 |
| 文档系统 | references/documentation-systems.md | 文档站点、静态生成器、搜索、测试 |
| 交互式 API 文档 | references/interactive-api-docs.md | OpenAPI 3.1、门户、GraphQL、WebSocket、gRPC、SDK |
| 用户指南和教程 | references/user-guides-tutorials.md | 入门指南、教程、故障排查、常见问题 |
约束
必须执行
- 开始前询问格式偏好
- 检测框架,以采用正确的 API 文档策略
- 为所有公共函数/类编写文档
- 包含参数类型和说明
- 记录异常/错误
- 测试文档中的代码示例
- 生成覆盖率报告
禁止执行
- 未经询问就假定文档字符串格式
- 对框架采用错误的 API 文档策略
- 编写不准确或未经测试的文档
- 跳过错误说明
- 对显而易见的 getter/setter 编写冗长文档
- 创建难以维护的文档
输出格式
根据任务提供:
- 代码文档: 已编写文档的文件 + 覆盖率报告
- API 文档: OpenAPI 规范 + 门户配置
- 文档站点: 站点配置 + 内容结构 + 构建说明
- 指南/教程: 结构化 Markdown,包含示例 + 图表
知识参考
Google/NumPy/Sphinx 文档字符串、JSDoc、OpenAPI 3.0/3.1、AsyncAPI、gRPC/protobuf、FastAPI、Django、NestJS、Express、GraphQL、Docusaurus、MkDocs、VitePress、Swagger UI、Redoc、Stoplight
评论
支持 Markdown