mcpField
D
documentation-audit

documentation-audit

github.com/troykelly开发1282 次安装41 周前更新
代码仓库

关于 documentation-audit

documentation-audit 是用于检测并修正文档与代码不同步的开发技能。它盘点 API 和功能,补建或更新文档,并验证文件格式。

主要功能

  1. 01发现文档文件与代码产物
  2. 02审计 API 端点和功能
  3. 03生成缺失的 OpenAPI 与功能文档
  4. 04更新现有文档并标注待审内容
  5. 05验证 YAML、JSON 和 Markdown

适用场景

  1. 01API 变更后检查文档是否过时
  2. 02补齐项目缺少的 API 或功能说明

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/troykelly/claude-skills --skill documentation-audit

安装后在 Claude Code 中输入/documentation-audit确认已加载。

详细介绍

文档审计

概述

检测到文档与代码不一致时,全面同步文档。分析代码库,并创建或更新所有文档资料,使其与代码库完全同步。

核心原则: 文档必须反映实际情况。此技能可使文档与实际情况保持一致。

开始时先说明:“我正在使用 documentation-audit 同步所有文档,使其与当前代码库保持一致。”

此技能的触发条件

以下情况会调用此技能:

触发条件来源
API 文档不一致api-documentation 技能
功能文档不一致features-documentation 技能
缺少文档文件任意文档检查
手动请求用户或协调器

审计流程

阶段 1:发现
echo "=== Documentation Audit: Discovery Phase ==="

# Find all documentation files
DOC_FILES=$(find . -name "*.md" -o -name "*.yaml" -o -name "*.json" | \
  grep -E "(doc|api|swagger|openapi|feature|guide|readme)" | \
  grep -v node_modules | grep -v .git)

echo "Found documentation files:"
echo "$DOC_FILES"

# Find API documentation
API_DOC=$(find . -name "openapi.yaml" -o -name "swagger.yaml" -o -name "openapi.json" | head -1)
echo "API Documentation: ${API_DOC:-MISSING}"

# Find features documentation
FEATURE_DOC=$(find . -name "features.md" -o -name "FEATURES.md" | head -1)
echo "Features Documentation: ${FEATURE_DOC:-MISSING}"
阶段 2:API 审计

如果存在 API 端点:

echo "=== Documentation Audit: API Phase ==="

# Detect API framework
detect_api_framework() {
  if grep -r "express" package.json 2>/dev/null; then echo "express"; return; fi
  if grep -r "fastify" package.json 2>/dev/null; then echo "fastify"; return; fi
  if grep -r "@nestjs" package.json 2>/dev/null; then echo "nestjs"; return; fi
  if grep -r "fastapi" requirements.txt 2>/dev/null; then echo "fastapi"; return; fi
  if grep -r "flask" requirements.txt 2>/dev/null; then echo "flask"; return; fi
  if [ -f "go.mod" ]; then echo "go"; return; fi
  echo "unknown"
}

FRAMEWORK=$(detect_api_framework)
echo "Detected framework: $FRAMEWORK"

# Extract all endpoints from code
extract_endpoints() {
  case "$FRAMEWORK" in
    express|fastify)
      grep -rh "app\.\(get\|post\|put\|delete\|patch\)" --include="*.ts" --include="*.js" | \
        sed "s/.*app\.\([a-z]*\)('\([^']*\)'.*/\1 \2/"
      ;;
    nestjs)
      grep -rh "@\(Get\|Post\|Put\|Delete\|Patch\)" --include="*.ts" | \
        sed "s/.*@\([A-Za-z]*\)('\([^']*\)'.*/\1 \2/"
      ;;
    fastapi)
      grep -rh "@app\.\(get\|post\|put\|delete\|patch\)" --include="*.py" | \
        sed "s/.*@app\.\([a-z]*\)(\"\([^\"]*\)\".*/\1 \2/"
      ;;
    *)
      echo "Unknown framework - manual inspection required"
      ;;
  esac
}

ENDPOINTS=$(extract_endpoints)
echo "Found endpoints:"
echo "$ENDPOINTS"
阶段 3:功能审计
echo "=== Documentation Audit: Features Phase ==="

# Find user-facing components
find_features() {
  # React components in pages/views
  find . -path "*/pages/*" -name "*.tsx" -o -path "*/views/*" -name "*.tsx" | \
    xargs -I {} basename {} .tsx 2>/dev/null

  # Feature flags
  grep -rh "featureFlag\|feature:" --include="*.ts" --include="*.tsx" | \
    sed "s/.*['\"]feature[':]\s*['\"]?\([^'\"]*\)['\"]?.*/\1/" 2>/dev/null

  # Config options exposed to users
  grep -rh "config\.\|settings\." --include="*.ts" | \
    grep -v "import\|require" | \
    sed "s/.*\(config\|settings\)\.\([a-zA-Z]*\).*/\2/" 2>/dev/null | sort -u
}

FEATURES=$(find_features)
echo "Discovered features:"
echo "$FEATURES"
阶段 4:生成缺失的文档
缺少 OpenAPI 时创建
# Template for new OpenAPI file
openapi: 3.0.3
info:
  title: [PROJECT_NAME] API
  description: |
    API documentation for [PROJECT_NAME].
    Generated by documentation-audit skill.
  version: 1.0.0
  contact:
    name: API Support
servers:
  - url: http://localhost:3000
    description: Development server
  - url: https://api.example.com
    description: Production server
paths:
  # Endpoints will be added here
components:
  schemas:
    Error:
      type: object
      properties:
        code:
          type: string
        message:
          type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
缺少功能文档时创建
# Features

> Generated by documentation-audit skill. Update with accurate descriptions.

## Overview

[Brief description of the product]

## Core Features

### [Feature 1]

**Description:** [What it does]

**How to Use:**
1. [Step 1]
2. [Step 2]

---

## Additional Features

[List additional features discovered]

---

*Last updated: [DATE]*
*Note: This file was auto-generated. Review and enhance descriptions.*
阶段 5:更新现有文档

对于每个已发现但未记录的项目:

  1. API 端点 — 在 OpenAPI 规范中添加:

    • 路径和方法
    • 参数(来自函数签名)
    • 请求体架构(来自 DTO/类型)
    • 响应架构(来自返回类型)
    • 基本说明
  2. 功能 — 在功能文档中添加:

    • 功能名称
    • 基本说明
    • 如何使用的占位内容
    • 提醒审阅并完善的注释
阶段 6:验证
echo "=== Documentation Audit: Validation Phase ==="

# Validate OpenAPI
if [ -f "openapi.yaml" ]; then
  yq '.' openapi.yaml > /dev/null 2>&1 && echo "OpenAPI: Valid YAML" || echo "OpenAPI: Invalid YAML"
fi

# Validate Markdown
for file in docs/*.md; do
  if [ -f "$file" ]; then
    # Check for required sections
    if ! grep -q "^## " "$file"; then
      echo "WARNING: $file missing section headers"
    fi
  fi
done

# Check completeness
ENDPOINTS_DOCUMENTED=$(yq '.paths | keys | length' openapi.yaml 2>/dev/null || echo 0)
ENDPOINTS_IN_CODE=$(extract_endpoints | wc -l)

echo "Endpoints in code: $ENDPOINTS_IN_CODE"
echo "Endpoints documented: $ENDPOINTS_DOCUMENTED"

if [ "$ENDPOINTS_DOCUMENTED" -lt "$ENDPOINTS_IN_CODE" ]; then
  echo "WARNING: Some endpoints still undocumented"
fi

审计报告

将审计结果发布到 GitHub issue:

## Documentation Audit Complete

**Audit Date:** [ISO_TIMESTAMP]
**Triggered By:** [api-documentation|features-documentation|manual]

### Summary

| Category | Before | After | Status |
|----------|--------|-------|--------|
| API Endpoints | [N] undocumented | [N] documented | [COMPLETE/PARTIAL] |
| Features | [N] undocumented | [N] documented | [COMPLETE/PARTIAL] |
| General Docs | [N] missing | [N] created | [COMPLETE/PARTIAL] |

### Files Created
- `openapi.yaml` - API documentation
- `docs/features.md` - Features documentation

### Files Updated
- `openapi.yaml` - Added [N] endpoints
- `docs/features.md` - Added [N] features

### Requires Manual Review
- [ ] Verify API response schemas
- [ ] Enhance feature descriptions
- [ ] Add usage examples
- [ ] Review security documentation

### Next Steps
1. Review generated documentation
2. Add detailed descriptions
3. Include examples
4. Validate with stakeholders

---
*documentation-audit skill completed*

检查清单

审计期间:

  • 已发现所有文档文件
  • 已检测 API 框架
  • 已从代码中提取所有端点
  • 已从代码中提取所有功能
  • 已创建缺失的文档文件
  • 已更新现有文档
  • 已验证所有文件
  • 已将审计报告发布到 issue
  • 已提交更改

质量标准

生成的文档必须符合以下要求:

标准要求
完整性列出每个端点/功能
有效性YAML/JSON 验证通过
结构包含必需章节
占位内容提供清晰的手动审阅标记
归属说明注明由技能生成

集成

调用此技能的场景:

技能时机
api-documentation检测到 API 不一致时
features-documentation检测到功能不一致时
issue-driven-development文档步骤

此技能使用以下工具:

工具用途
Glob/Grep发现代码资料
Read分析现有文档
Write创建新文档
Edit更新现有文档
yq验证 YAML
jq验证 JSON

评论

支持 Markdown