Skip to content

Add concise-comments skill; wire into /spec & /process-reviews - #9

Open
ZmeiGorynych wants to merge 1 commit into
masterfrom
egor/concise-comments-skill
Open

Add concise-comments skill; wire into /spec & /process-reviews#9
ZmeiGorynych wants to merge 1 commit into
masterfrom
egor/concise-comments-skill

Conversation

@ZmeiGorynych

@ZmeiGorynych ZmeiGorynych commented Aug 11, 2026

Copy link
Copy Markdown
Member

What

Adds a concise-comments skill that captures the rules for keeping code comments/docstrings terse, and provides a /concise-comments pass to trim over-verbose ones from existing code.

  • skills/concise-comments/SKILL.md — the test ("could a reader of this codebase infer it?"), what comments are for vs. what belongs in the PR/DECISIONS/issue/tests, hard line limits, a delete-on-sight anti-pattern list, and the trimming-pass workflow (scope → edit comments-only → verify tests/lint + comment-only diff → measure).
  • skills/concise-comments/scripts/count_comments.py — counts comment + docstring lines (tokenize for #, AST for docstrings); supports --range <ref> for net-added over a git range, to measure reduction.

Prevention wiring

  • /spec — implement/test steps now say to follow concise-comments so bloat isn't written in the first place.
  • /process-reviews — over-verbose comments are a valid maintainability finding to flag; fix-time comments must stay concise.

Origin

Distilled from a real cleanup (SLayer DEV-1756) that cut added comment/docstring lines ~3.1× with the code AST provably unchanged.

Note: skills/spec/SKILL.md also carries a pre-existing local refinement (pros/cons/recommendation on every choice), which rides along in the same file.

Summary by CodeRabbit

  • New Features

    • Added guidance for keeping code comments and docstrings concise, focused on non-obvious information, and free of unnecessary rationale.
    • Added a command-line tool to count comments and docstrings, including comparisons against a previous revision.
  • Documentation

    • Updated review guidance to identify overly verbose comments as maintainability issues.
    • Added requirements for decision prompts to include pros, cons, and a recommendation.

New skill with the rules for terse comments/docstrings (limits +
delete-on-sight anti-patterns) and a `/concise-comments` trimming pass,
plus scripts/count_comments.py to measure reduction. Referenced from
/spec (write step) and /process-reviews (validate + fix) so verbose
comments are caught early. spec/SKILL.md also carries the local
pros/cons-in-choices refinement.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This change adds a concise-comments skill and a Python utility for counting comments and docstrings. It also updates review validation and specification rules to require concise comments and explicit recommendations.

Changes

Concise Comments

Layer / File(s) Summary
Concise-comment skill definition
skills/concise-comments/SKILL.md
Defines comment-retention criteria, length limits, cleanup workflow, verification steps, and scaling guidance.
Comment counting utility
skills/concise-comments/scripts/count_comments.py
Counts Python comments and docstrings per file, compares working-tree counts with Git references, handles unavailable or invalid sources, and reports CLI results.
Review and specification integration
skills/process-reviews/SKILL.md, skills/spec/SKILL.md
Flags verbose or code-restating comments, requires concise comments in fixes, and requires decision prompts to include pros, cons, and a recommendation.

Estimated code review effort: 2 (Simple) | ~15 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding the concise-comments skill and integrating it with /spec and /process-reviews.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch egor/concise-comments-skill

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (1)
skills/concise-comments/scripts/count_comments.py (1)

26-31: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Narrow the exception handlers.

The two except Exception blocks turn unexpected failures into valid-looking counts. Catch only the expected tokenization and AST parse errors. Let unexpected failures surface.

Suggested direction
-    except Exception:
+    except (tokenize.TokenError, IndentationError):
...
-    except Exception:
+    except (SyntaxError, ValueError):
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@skills/concise-comments/scripts/count_comments.py` around lines 26 - 31,
Replace the broad exception handlers in the comment-counting logic with only the
expected tokenization error for the tokenization path and AST parse error for
the ast.parse path. Preserve the fallback counts for those expected failures,
while allowing all other exceptions to propagate.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@skills/concise-comments/scripts/count_comments.py`:
- Around line 65-71: Update the reporting logic around counts(), the per-file
print, and the final total print so --range output includes comment and
docstring before→after counts and the required ratio, matching the report
contract in SKILL.md. Define and consistently apply behavior for a zero baseline
ratio; alternatively, update the documented requirement to explicitly permit
delta-only output.
- Around line 59-62: Update main so the --range branch validates that argv
contains both a reference and at least one path before accessing argv[1] or
assigning paths. Return the existing usage-error result for missing arguments,
while preserving the current range processing when both are supplied.
- Line 18: Add comprehensive tests for the utility centered on counts, covering
valid and malformed Python, module/class/function/async docstrings, missing
files, invalid Git references, deleted paths, and incomplete --range CLI
arguments. Verify expected counts and error behavior for each case, including
both valid and malformed inputs.
- Around line 52-56: Update read so missing files raise an error in normal mode
instead of returning None, while allowing None for intentionally missing
working-tree paths when --range deletion analysis is active. Thread the mode or
range context through the callers of read and preserve the existing
deletion-count behavior.
- Around line 47-49: Update git_show to validate the Git ref separately before
reading ref:path, preserving distinct handling for invalid refs and missing
paths. Return None only when the reference is valid but the requested path is
unavailable, and ensure invalid refs do not become empty content that is
interpreted as additions.

---

Nitpick comments:
In `@skills/concise-comments/scripts/count_comments.py`:
- Around line 26-31: Replace the broad exception handlers in the
comment-counting logic with only the expected tokenization error for the
tokenization path and AST parse error for the ast.parse path. Preserve the
fallback counts for those expected failures, while allowing all other exceptions
to propagate.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: df945488-faa0-4427-bda0-4bf850cf8d65

📥 Commits

Reviewing files that changed from the base of the PR and between 686c1a3 and ae08849.

📒 Files selected for processing (4)
  • skills/concise-comments/SKILL.md
  • skills/concise-comments/scripts/count_comments.py
  • skills/process-reviews/SKILL.md
  • skills/spec/SKILL.md

import tokenize


def counts(src: str | None) -> tuple[int, int]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Add solid tests for the shipped utility.

This change adds parsing, Git-reference, file, and CLI behavior without adding tests. Cover valid and malformed Python, module/class/function/async docstrings, missing files, invalid refs, deleted paths, and incomplete --range arguments.

As per coding guidelines: “Whenever you do any changes to production code ... ALWAYS add solid test coverage for it.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@skills/concise-comments/scripts/count_comments.py` at line 18, Add
comprehensive tests for the utility centered on counts, covering valid and
malformed Python, module/class/function/async docstrings, missing files, invalid
Git references, deleted paths, and incomplete --range CLI arguments. Verify
expected counts and error behavior for each case, including both valid and
malformed inputs.

Source: Coding guidelines

Comment on lines +47 to +49
def git_show(ref: str, path: str) -> str | None:
r = subprocess.run(["git", "show", f"{ref}:{path}"], capture_output=True, text=True)
return r.stdout if r.returncode == 0 else None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- file map ---'
ast-grep outline skills/concise-comments/scripts/count_comments.py

printf '%s\n' '--- relevant source ---'
cat -n skills/concise-comments/scripts/count_comments.py | sed -n '1,140p'

printf '%s\n' '--- tracked related files ---'
git ls-files | rg '(^|/)(count_comments|test|tests)' | head -100

printf '%s\n' '--- structural references to git_show ---'
ast-grep run --lang python --pattern 'git_show($_, $_)' skills/concise-comments/scripts/count_comments.py

Repository: MotleyAI/claude-configs

Length of output: 3891


🏁 Script executed:

#!/bin/bash
set -eu

python3 - <<'PY'
import subprocess

def git_show(ref: str, path: str):
    r = subprocess.run(
        ["git", "show", f"{ref}:{path}"],
        capture_output=True,
        text=True,
    )
    return r.stdout if r.returncode == 0 else None, r.returncode, r.stderr.strip()

head = subprocess.run(
    ["git", "rev-parse", "--verify", "HEAD"],
    capture_output=True,
    text=True,
    check=True,
).stdout.strip()

cases = [
    ("invalid-ref", "HEAD_DOES_NOT_EXIST", "skills/concise-comments/scripts/count_comments.py"),
    ("missing-path", head, "skills/concise-comments/scripts/path_does_not_exist.py"),
    ("valid-path", head, "skills/concise-comments/scripts/count_comments.py"),
]
for name, ref, path in cases:
    value, code, error = git_show(ref, path)
    print(f"{name}: returncode={code}, result_is_none={value is None}, stdout_len={len(value or '')}, stderr={error!r}")
PY

Repository: MotleyAI/claude-configs

Length of output: 563


Validate the Git reference before reading the file. git_show maps both invalid references and missing paths to None, so an invalid ref produces false additions. Validate ref separately, then treat only a missing ref:path as empty content.

🧰 Tools
🪛 ast-grep (0.45.1)

[error] 47-47: Command coming from incoming request
Context: subprocess.run(["git", "show", f"{ref}:{path}"], capture_output=True, text=True)
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

(subprocess-from-request)

🪛 Ruff (0.16.1)

[error] 48-48: subprocess call: check for execution of untrusted input

(S603)


[error] 48-48: Starting a process with a partial executable path

(S607)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@skills/concise-comments/scripts/count_comments.py` around lines 47 - 49,
Update git_show to validate the Git ref separately before reading ref:path,
preserving distinct handling for invalid refs and missing paths. Return None
only when the reference is valid but the requested path is unavailable, and
ensure invalid refs do not become empty content that is interpreted as
additions.

Comment on lines +52 to +56
def read(path: str) -> str | None:
try:
return open(path, encoding="utf-8").read()
except FileNotFoundError:
return None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Make missing-file handling mode-aware.

read maps FileNotFoundError to None, so normal mode reports a misspelled path as a successful zero count. Fail for missing paths in normal mode. Allow missing working-tree paths only when --range intentionally measures deletions.

Also applies to: 77-79

🧰 Tools
🪛 ast-grep (0.45.1)

[warning] 53-53: File path is request-/variable-derived; validate and normalize to prevent path traversal.
Context: open(path, encoding="utf-8")
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(open-filename-from-request)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@skills/concise-comments/scripts/count_comments.py` around lines 52 - 56,
Update read so missing files raise an error in normal mode instead of returning
None, while allowing None for intentionally missing working-tree paths when
--range deletion analysis is active. Thread the mode or range context through
the callers of read and preserve the existing deletion-count behavior.

Comment on lines +59 to +62
def main(argv: list[str]) -> int:
if argv and argv[0] == "--range":
ref = argv[1]
paths = argv[2:]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Validate --range arguments before indexing argv.

--range without a reference raises IndexError. --range REF also lacks a required path. Return a usage error unless both a reference and at least one path are present.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@skills/concise-comments/scripts/count_comments.py` around lines 59 - 62,
Update main so the --range branch validates that argv contains both a reference
and at least one path before accessing argv[1] or assigning paths. Return the
existing usage-error result for missing arguments, while preserving the current
range processing when both are supplied.

Comment on lines +65 to +71
b = counts(git_show(ref, p))
h = counts(read(p))
dc, dd = h[0] - b[0], h[1] - b[1]
print(f"{dc + dd:+5d} comment={dc:+4d} doc={dd:+4d} {p}")
tc += dc
td += dd
print(f"{'=' * 50}\nNET ADDED total={tc + td} (comment {tc}, docstring {td})")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Align --range output with the skill’s report contract.

This branch prints only deltas. skills/concise-comments/SKILL.md Line 39 requires per-file and total before→after counts plus a ratio. Print those values and define the zero-baseline ratio, or change the skill requirement to match the delta-only output.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@skills/concise-comments/scripts/count_comments.py` around lines 65 - 71,
Update the reporting logic around counts(), the per-file print, and the final
total print so --range output includes comment and docstring before→after counts
and the required ratio, matching the report contract in SKILL.md. Define and
consistently apply behavior for a zero baseline ratio; alternatively, update the
documented requirement to explicitly permit delta-only output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant