Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

code-documentation代码文档

Agent Skill

用于辅助文档、README、Markdown、说明文和内容稿件的整理与改写。它适合让 Agent 提炼结构、补齐章节、统一术语、检查链接或把零散材料整理成可读文档。使用时应保留项目已有事实、命令和路径,不要把未确认的信息写成确定结论;涉及对外文案时,还需要控制语气,避免过度营销或夸大能力。

总安装

297

周安装

12

GitHub Stars

7

下载量

93
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:code-documentation(代码文档)
来源仓库:https://github.com/ilude/claude-code-config
仓库路径:skills/code-documentation
安装命令:
npx skills add https://github.com/ilude/claude-code-config --skill code-documentation
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/ilude/claude-code-config --skill code-documentation

简介

优先顺序:

  • 清晰的代码 - 通过命名和结构不言自明
  • 好的评论 - 必要时解释原因
  • 文档 - API 文档、公共接口的文档字符串
  • 没有评论 - 比撒谎或混乱的坏评论好
  • 请记住:注释无法使代码不言自明。谨慎而明智地使用它们。
  • 要点
  • 目标
  • 方法
  • 减少评论
  • 改进命名、提取功能、简化逻辑
  • 提高清晰度
  • 使用不言自明的代码结构,清晰的变量名称
  • 文档 API
  • 使用 docstrings/JSDoc 作为公共接口
  • 解释为什么
  • 仅评论业务逻辑、算法、解决方法
  • 保持准确性
  • 代码更改时更新注释,或删除它们
  • 每周安装量
  • 12
  • 存储库
  • ilude/claude-代码配置
  • GitHub 之星
  • 7
  • 第一次看到
  • 2026 年 1 月 23 日
  • 安全审计
  • Gen Agent Trust Hub 通行证
  • 套接字通行证
  • 斯尼克通行证

SKILL.md

Code Documentation & Self-Explanatory Code

Auto-activate when: User discusses comments, documentation, docstrings, code clarity, code quality, API docs, JSDoc, Python docstrings, or asks about commenting strategies.

Core Principle

Write code that speaks for itself. Comment only when necessary to explain WHY, not WHAT.

Most code does not need comments. Well-written code with clear naming and structure is self-documenting.

The best comment is the one you don't need to write because the code is already obvious.


The Commenting Philosophy

When to Comment

DO comment when explaining:

  • WHY something is done (business logic, design decisions)
  • Complex algorithms and their reasoning
  • Non-obvious trade-offs or constraints
  • Workarounds for bugs or limitations
  • API contracts and public interfaces
  • Regex patterns and what they match
  • Performance considerations or optimizations
  • Constants and magic numbers
  • Gotchas or surprising behaviors

DON'T comment when:

  • The code is obvious and self-explanatory
  • The comment repeats the code (redundant)
  • Better naming would eliminate the need
  • The comment would become outdated quickly
  • It's decorative or organizational noise
  • It states what a standard language construct does

Comment Anti-Patterns

❌ 1. Obvious Comments

BAD:

counter = 0  # Initialize counter to zero
counter += 1  # Increment counter by one
user_name = input("Enter name: ")  # Get user name from input

Better: No comment needed - the code is self-explanatory.


❌ 2. Redundant Comments

BAD:

def get_user_name(user):
    return user.name  # Return the user's name

def calculate_total(items):
    # Loop through items and sum the prices
    total = 0
    for item in items:
        total += item.price
    return total

Better:

def get_user_name(user):
    return user.name

def calculate_total(items):
    return sum(item.price for item in items)

❌ 3. Outdated Comments

BAD:

# Calculate tax at 5% rate
tax = price * 0.08  # Actually 8%, comment is wrong

# DEPRECATED: Use new_api_function() instead
def old_function():  # Still being used, comment is misleading
    pass

Better: Keep comments in sync with code, or remove them entirely.


❌ 4. Noise Comments

BAD:

# Start of function
def calculate():
    # Declare variable
    result = 0
    # Return result
    return result
# End of function

Better: Remove all of these comments.


❌ 5. Dead Code & Changelog Comments

BAD:

# Don't comment out code - use version control
# def old_function():
#     return "deprecated"

# Don't maintain history in comments
# Modified by John on 2023-01-15
# Fixed bug reported by Sarah on 2023-02-03

Better: Delete the code. Git has the history.


Good Comment Examples

✅ Complex Business Logic

# Apply progressive tax brackets: 10% up to $10k, 20% above
# This matches IRS publication 501 for 2024
def calculate_progressive_tax(income):
    if income <= 10000:
        return income * 0.10
    else:
        return 1000 + (income - 10000) * 0.20

✅ Non-obvious Algorithms

# Using Floyd-Warshall for all-pairs shortest paths
# because we need distances between all nodes.
# Time: O(n³), Space: O(n²)
for k in range(vertices):
    for i in range(vertices):
        for j in range(vertices):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

✅ Regex Patterns

# Match email format: username@domain.extension
# Allows letters, numbers, dots, hyphens in username
# Requires valid domain and 2+ char extension
email_pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'

✅ API Constraints or Gotchas

# GitHub API rate limit: 5000 requests/hour for authenticated users
# We implement exponential backoff to handle rate limiting
await rate_limiter.wait()
response = await fetch(github_api_url)

✅ Workarounds for Bugs

# HACK: Workaround for bug in library v2.1.0
# Remove after upgrading to v2.2.0
# See: https://github.com/library/issues/123
if library_version == "2.1.0":
    apply_workaround()

Decision Framework

Before writing a comment, ask yourself:

Step 1: Is the code self-explanatory?

  • If YES → No comment needed
  • If NO → Continue to step 2

Step 2: Would a better variable/function name eliminate the need?

  • If YES → Refactor the code instead
  • If NO → Continue to step 3

Step 3: Does this explain WHY, not WHAT?

  • If explaining WHAT → Refactor code to be clearer
  • If explaining WHY → Good comment candidate

Step 4: Will this help future maintainers?

  • If YES → Write the comment
  • If NO → Skip it

Special Cases for Comments

Public APIs and Docstrings

Python Docstrings

def calculate_compound_interest(
    principal: float,
    rate: float,
    time: int,
    compound_frequency: int = 1
) -> float:
    """
    Calculate compound interest using the standard formula.

    Args:
        principal: Initial amount invested
        rate: Annual interest rate as decimal (e.g., 0.05 for 5%)
        time: Time period in years
        compound_frequency: Times per year interest compounds (default: 1)

    Returns:
        Final amount after compound interest

    Raises:
        ValueError: If any parameter is negative

    Example:
        >>> calculate_compound_interest(1000, 0.05, 10)
        1628.89
    """
    if principal < 0 or rate < 0 or time < 0:
        raise ValueError("Parameters must be non-negative")

    # Compound interest formula: A = P(1 + r/n)^(nt)
    return principal * (1 + rate / compound_frequency) ** (compound_frequency * time)

JavaScript/TypeScript JSDoc

/**
 * Fetch user data from the API.
 *
 * @param {string} userId - The unique user identifier
 * @param {Object} options - Configuration options
 * @param {boolean} options.includeProfile - Include profile data (default: true)
 * @param {number} options.timeout - Request timeout in ms (default: 5000)
 *
 * @returns {Promise<User>} User object with requested fields
 *
 * @throws {Error} If userId is invalid or request fails
 *
 * @example
 * const user = await fetchUser('123', { includeProfile: true });
 */
async function fetchUser(userId, options = {}) {
  // Implementation
}

Constants and Configuration

# Based on network reliability studies (95th percentile)
MAX_RETRIES = 3

# AWS Lambda timeout is 15s, leaving 5s buffer for cleanup
API_TIMEOUT = 10000  # milliseconds

# Cache duration optimized for balance between freshness and load
# See: docs/performance-tuning.md
CACHE_TTL = 300  # 5 minutes

Annotations for TODOs and Warnings

# TODO: Replace with proper authentication after security review
# Issue: #456
def temporary_auth(user):
    return True

# WARNING: This function modifies the original array instead of creating a copy
def sort_in_place(arr):
    arr.sort()
    return arr

# FIXME: Memory leak in production - investigate connection pooling
# Ticket: JIRA-789
def get_connection():
    return create_connection()

# PERF: Consider caching this result if called frequently in hot path
def expensive_calculation(data):
    return complex_algorithm(data)

# SECURITY: Validate input to prevent SQL injection before using in query
def build_query(user_input):
    sanitized = escape_sql(user_input)
    return f"SELECT * FROM users WHERE name = '{sanitized}'"

Common Annotation Keywords

  • TODO: - Work that needs to be done
  • FIXME: - Known bugs that need fixing
  • HACK: - Temporary workarounds
  • NOTE: - Important information or context
  • WARNING: - Critical information about usage
  • PERF: - Performance considerations
  • SECURITY: - Security-related notes
  • BUG: - Known bug documentation
  • REFACTOR: - Code that needs refactoring
  • DEPRECATED: - Soon-to-be-removed code

Refactoring Over Commenting

Instead of Commenting Complex Code...

BAD: Complex code with comment

# Check if user is admin or has special permissions
if user.role == "admin" or (user.permissions and "special" in user.permissions):
    grant_access()

...Extract to Named Function

GOOD: Self-explanatory through naming

def user_has_admin_access(user):
    return user.role == "admin" or has_special_permission(user)

def has_special_permission(user):
    return user.permissions and "special" in user.permissions

if user_has_admin_access(user):
    grant_access()

Language-Specific Examples

JavaScript

// Good: Explains WHY we debounce
// Debounce search to reduce API calls (500ms wait after last keystroke)
const debouncedSearch = debounce(searchAPI, 500);

// Bad: Obvious
let count = 0;  // Initialize count to zero
count++;  // Increment count

// Good: Explains algorithm choice
// Using Set for O(1) lookup instead of Array.includes() which is O(n)
const seen = new Set(ids);

Python

# Good: Explains the algorithm choice
# Using binary search because data is sorted and we need O(log n) performance
index = bisect.bisect_left(sorted_list, target)

# Bad: Redundant
def get_total(items):
    return sum(items)  # Return the sum of items

# Good: Explains why we're doing this
# Extract to separate function for type checking in mypy
def validate_user(user):
    if not user or not user.id:
        raise ValueError("Invalid user")
    return user

TypeScript

// Good: Explains the type assertion
// TypeScript can't infer this is never null after the check
const element = document.getElementById('app') as HTMLElement;

// Bad: Obvious
const sum = a + b;  // Add a and b

// Good: Explains non-obvious behavior
// spread operator creates shallow copy; use JSON for deep copy
const newConfig = { ...config };

Comment Quality Checklist

Before committing, ensure your comments:

  • Explain WHY, not WHAT
  • Are grammatically correct and clear
  • Will remain accurate as code evolves
  • Add genuine value to code understanding
  • Are placed appropriately (above the code they describe)
  • Use proper spelling and professional language
  • Follow team conventions for annotation keywords
  • Could not be replaced by better naming or structure
  • Are not obvious statements about language features
  • Reference tickets/issues when applicable

Summary

Priority order:

  1. Clear code - Self-explanatory through naming and structure
  2. Good comments - Explain WHY when necessary
  3. Documentation - API docs, docstrings for public interfaces
  4. No comments - Better than bad comments that lie or clutter

Remember: Comments are a failure to make the code self-explanatory. Use them sparingly and wisely.


Key Takeaways

GoalApproach
Reduce commentsImprove naming, extract functions, simplify logic
Improve clarityUse self-explanatory code structure, clear variable names
Document APIsUse docstrings/JSDoc for public interfaces
Explain WHYComment only business logic, algorithms, workarounds
Maintain accuracyUpdate comments when code changes, or remove them

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.94%
按下载量换算34

Claude

30.44%
按下载量换算28

Cursor

19.17%
按下载量换算18

Gemini CLI

9.43%
按下载量换算9

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills