agentleFS
Sir-chawakornSir-chawakorn/sanook-cli/skills/code-comments/SKILL.md

code-comments

Skill9 starsChanged 5 months agoApache-2.0View on GitHub

Adds high-signal code comments and docstrings that explain WHY (intent, invariants, gotchas) rather than restating WHAT, in the language's idiomatic doc format (JSDoc/TSDoc, Google/NumPy Python docstrings, rustdoc, godoc) — without over-commenting.

17 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 3 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 15 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    NOT for prose docs (README/guides/API pages) — that's write-docs.

    line 12
  2. Distinctive:

    NOT a refactor — if logic looks wrong, flag it separately.

    line 13
  3. Distinctive:

    Read the full unit first: Read the whole function/module before writing a single comment.

    line 17
  4. Distinctive:

    Write the docstring in the language's idiomatic format: Use the existing convention in the file/repo if one is present (match it).

    line 21
  5. Very specific:

    Doctests pass: if you added any runnable examples (pytest --doctest-modules, cargo test --doc).

    line 50

“Common” is measured: kept by at least 6 in 10 of the 15 edited versions of this file we could read. “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

When to Use

  • User says "comment this", "add docstrings", "document this function/module/class", or "explain this tricky block".
  • Prepping code for handoff or review where intent isn't obvious.
  • Legacy code with zero comments where you must infer and record WHY.
  • NOT for prose docs (README/guides/API pages) — that's write-docs.
  • NOT a refactor — if logic looks wrong, flag it separately; this skill changes comments only.

Steps

  1. Read the full unit first. Read the whole function/module before writing a single comment. Trace data flow, error paths, and callers (grep for usages) so you comment real intent, not a guess. If intent is genuinely unrecoverable, write // FIXME: intent unclear — <specific question> instead of inventing a rationale.
  2. Mark only the non-obvious. Tag lines/blocks where WHY ≠ WHAT: magic numbers, off-by-one guards, ret/ timeout / backoff constants, workarounds for upstream bugs, ordering that looks swappable but isn't, perf hacks, locking/concurrency assumptions, security checks. Skip anything a competent reader infers from the code itself.
  3. Write the docstring in the language's idiomatic format. Use the existing convention in the file/repo if one is present (match it). Otherwise default to:
    • TS/JS → TSDoc/JSDoc: one-line summary, then @param, @returns, @throws. Omit @param types in TS (the type is in the signature) — describe meaning/constraints/units instead.
    • Python → match repo (Google or NumPy). Sections: summary, Args:/Parameters, Returns:, Raises:. Add Examples: (doctest-style) only for non-trivial contracts.
    • Rust → rustdoc ///: summary, # Arguments (when non-obvious), # Errors, # Panics, # Safety for unsafe. # Examples should be compilable.
    • Go → godoc: comment starts with the identifier name (// Foo does ...), full sentences, period-terminated.
  4. Put the signal in the docstring, not the body. Document: units (ms vs s, bytes vs KB), valid ranges, nullability, ownership/lifetime, side effects, thread-safety, idempotency, and what each error/exception actually means for the caller. These are the things callers can't see from the signature.
  5. Inline comments only for surprising WHY. One line, above the code (not trailing, unless very short). Good: // Retry 3x — upstream returns 503 on cold start. Bad: // loop over items. Prefer # TODO(context) / # HACK: / # SAFETY: tags so they're greppable.
  6. Delete redundant and stale comments you encounter. While editing, remove comments that restate code, are commented-out dead code, or contradict current behavior (stale comments are worse than none). Don't expand scope hunting the whole repo — just clean what's in your editing path.
  7. Keep the diff comment-only. Zero logic, formatting, or whitespace changes beyond the comments themselves. The diff must be reviewable as "comments added/removed" and nothing else.

Common Errors

  • Restating WHAT. i++ // increment i, return user // return the user. If the comment is the code in English, delete it.
  • Inventing rationale. Writing a confident "why" you didn't verify. If you can't confirm intent from code + callers, say so (FIXME: intent unclear) — a wrong comment is a future bug.
  • Over-commenting. Docstring on every trivial getter/setter, comment on every line. Noise drowns the 3 comments that matter. Comment the surprising, skip the obvious.
  • Wrong format / mixing conventions. JSDoc in a Python file, NumPy sections in a Google-style repo, /** */ in Go. Match the file's existing style; if none, use the language default above.
  • Duplicating types in TS JSDoc. @param {string} name when the signature already says name: string — drift risk when the type changes. Describe meaning, not type.
  • Touching logic. "Improving" a line while commenting it. Any behavior change voids the comment-only contract — stop and split it out.
  • Stale-comment blindness. Adding new docstrings while leaving an old comment that now lies. Reconcile or delete the old one.
  • Commenting the wrong layer. Explaining a workaround in the body when the caller needs it — put caller-facing contracts (raises, side effects, units) in the docstring where callers actually read them.

Verify

  1. Diff is comment-only — git diff shows only added/removed comment lines and docstrings; no logic, no reordering, no reformatting. If logic changed, revert it.
  2. Still compiles / lints — run the build or doc-comment linter (e.g. tsc --noEmit, ruff/pydocstyle, cargo doc, go vet). Malformed docstrings (bad @param, broken rustdoc # Examples) must pass.
  3. Doctests pass if you added any runnable examples (pytest --doctest-modules, cargo test --doc).
  4. WHY-not-WHAT scan — reread each added comment: does it tell the reader something the code doesn't already say? Delete any that fail.
  5. No invented facts — every "because/to avoid/upstream bug" is traceable to the code or an explicit FIXME, not a guess.

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.