agentleFS
SID-SURANGESID-SURANGE/cursor-team-ops/skills/core/document-this/SKILL.md

document-this

Skill0 starsChanged 4 months agoMITView on GitHub

Add why-only comments or docstrings to a function, class, or module. Writes comments that explain intent and constraints — not what the code does. Triggered by "document this function", "add comments", "write docstrings", "document-this".

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 6 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Add comments that carry information the code cannot.

    line 9
  2. Distinctive:

    Read the function, class, or module the user pointed at.

    line 38
  3. Distinctive:

    If none of the above apply to a section, write no comment for it.

    line 48
  4. Distinctive:

    Place inline comments on the line they explain, or on the line above.

    line 70
  5. Distinctive:

    Keep each comment short — one to two lines.

    line 71
  6. Distinctive:

    Do not apply until confirmed.

    line 77

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

📖 Skill: document-this

Purpose

Add comments that carry information the code cannot. The "why" — the constraint, the invariant, the non-obvious tradeoff — is the only thing worth writing. What the code does is already in the code.

This skill enforces the discipline the deslop skill removes: do not write narrating comments that restate the code in English.

Trigger phrases

  • "document this function"
  • "add comments"
  • "write docstrings"
  • "document-this"
  • "add JSDoc"
  • "add a docstring to this"
  • "explain why this works this way"

The rule

Write a comment if and only if removing it would leave a future reader confused about WHY — not WHAT.

Write itSkip it
Why this algorithm instead of the obvious oneWhat the loop does (the loop says it)
What invariant must hold when this is calledWhat the parameter means (the name says it)
Why this magic number (business rule, standard, bug workaround)That the function returns a value
What breaks silently if you change the orderThat this is a helper function
Which upstream bug this works aroundThat the class represents a user

Steps

1. Read the target

Read the function, class, or module the user pointed at. Do not infer scope — ask if unclear.

2. Identify comment-worthy facts

For each section of code, ask:

  • Is there a non-obvious constraint? (call order, thread safety, size limit, encoding assumption)
  • Is there a tradeoff the next person would re-litigate without context? (O(n²) that's fine because n < 50, a cache that must stay warm)
  • Is there a workaround for an external bug, API quirk, or spec gap?
  • Is there a business rule that looks like a magic number?

If none of the above apply to a section, write no comment for it.

3. Choose the format

Language / contextFormat
JavaScript / TypeScript (exported)JSDoc /** */ on the function/class
JavaScript / TypeScript (internal)Single-line // above the relevant line
Python (public function/class)Docstring """...""" immediately inside
Python (internal)# comment above the relevant line
Go// comment on the exported symbol
OtherMatch the file's existing comment style

For JSDoc/docstrings on exported symbols, include:

  • One sentence: why this exists (not what it does)
  • @param lines only when the type or constraint is non-obvious
  • @returns only when the return value has a non-obvious meaning or invariant
  • @throws only when the caller must handle a specific error case

4. Write comments, not rewrites

  • Touch only comments. Do not rename, reformat, or restructure any code.
  • Place inline comments on the line they explain, or on the line above.
  • Keep each comment short — one to two lines. If you need three, the code needs restructuring, not a comment.

5. Present for review

Show the diff (old → new) before applying. Say: "These comments explain the why — ready to apply?"

Do not apply until confirmed.

Output

A minimal diff adding comments only. No logic changes.

Example

Before:

def retry(fn, n=3, delay=1.5):
    for i in range(n):
        try:
            return fn()
        except Exception:
            if i == n - 1:
                raise
            time.sleep(delay * (2 ** i))

After (document-this applied):

def retry(fn, n=3, delay=1.5):
    # Exponential back-off: each retry waits 1.5× longer to avoid thundering-herd
    # on the upstream rate limiter, which resets on a fixed 2s window.
    for i in range(n):
        try:
            return fn()
        except Exception:
            if i == n - 1:
                raise
            time.sleep(delay * (2 ** i))

Note: the loop body itself needs no comment — it is self-evident.

Gotchas

  • Inferring "why" from the function name or body alone risks encoding a guess as fact — if the rationale isn't evident from the code itself (a linked issue, a commit message, an adjacent comment), check call sites or git blame before asserting a reason, or write the constraint you can verify ("must be called after X" — observable) instead of the motivation you can't ("because the API changed" — unverified).
  • A "why" comment written before behavior is fully understood can encode a wrong belief that outlives the mistake — if the function is unclear even after reading it, say so and ask rather than guessing at intent.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.