Skip to content

feat(comments): the codemod for the mechanical sweep tiers, and two fixes it exposed - #105

Merged
Ardnived merged 1 commit into
mainfrom
claude/comment-sweep-tool
Sep 16, 2026
Merged

Ardnived merged 1 commit into
mainfrom
claude/comment-sweep-tool

Conversation

@Ardnived

Copy link
Copy Markdown
Contributor

Merge this before the SahajCloud sweep PR — that PR's diff is this tool's output.

What it does

comment-sweep.mjs runs the three sweep tiers that need no judgement:

Tier Does On SahajCloud
1 Three-line banner becomes one line, label kept 43 files, 445 lines
2 One-line JSDoc block becomes a one-line JSDoc 58 files, 412 lines
3 Delete a comment whose every word the next line says 17 files, 64 lines

Tier 5 is deliberately absent. Compressing a bloated why down to the fact a reader needs requires a model that has read the surrounding code. The point of this tool is that the model spends its attention there instead of on scaffolding.

Two defects in the already-merged tools, both found by running them

leafTokens treated JSDoc as code. TypeScript hangs a JSDoc node off the declaration it documents, and getChildren() returns it — so a doc comment entered the token stream the anchor check compares. Every JSDoc edit then looked like it had moved the next comment. Collapsing one block reported // --- Constants --- below it as DISPLACED, in a file whose code was provably untouched. Six false positives in one run. The walk now skips the JSDoc subtree.

--repo refused a relative path. createRequire needs an absolute one, so --repo . threw. Fixed in all three tools.

Every sweep rule earned its guard by breaking something first

This is the part worth reviewing. Each guard exists because the unguarded rule damaged real comments on a real run, and each is documented in its own comment:

  • Banners are exempt from tier 3. A banner's label naturally repeats the identifiers in the section below it — exactly what the rule scores as restatement. Unguarded, it deleted the banners tier 1 had written in the same run.
  • Trailing comments are exempt. They carry what a literal cannot say about itself. width: 0, // Dimension extraction disabled and meditationTitleMap: Map<…> // meditation title → Meditation ID both died to the unguarded rule.
  • Only an isolated comment is eligible. A // run is one comment wearing several line markers. Scoring its last line alone deleted // listing. off the end of a four-line rationale, leaving "a region manager cannot act on the".
  • Tier 2 takes only a block whose prose is exactly one line. Splitting on sentence punctuation looked equivalent and was not — a wrapped line that simply ends without a full stop reads as one sentence to a regex, and joining Admin password for seed scripts authentication to Minimum 8 characters produced a run-on with two facts and no punctuation between them.

The pattern is the asymmetry the cleanup rule already states: wrongly deleting a real comment costs far more than leaving a mediocre one, so every ambiguous case reports a candidate instead of acting. Tier 3 surfaced 294 candidates on SahajCloud and deleted 17 files' worth.

Verification

  • comment-fingerprint.mjs --selftest — 9/9, both directions
  • comment-lint.mjs --selftest — 11/11, catching and sparing
  • claude plugin validate ./workflow --strict — passes
  • End to end on SahajCloud: 90 files changed, all 90 codeHash-identical, no comment displaced, every protected count unchanged

Version 2.1.0 → 2.2.0.

🤖 Generated with Claude Code

…ixes it exposed

`comment-sweep.mjs` does the three tiers of a comment sweep that need no
judgement: collapse a three-line banner to one line keeping its label, collapse
a one-line JSDoc block to a one-line JSDoc, and delete a comment whose every
word the next line already says. Tier 5 — compressing a bloated *why* — stays
with a model that has read the code, and is deliberately not here.

Proven on SahajCloud: 90 files, 1,347 deletions, 426 insertions, and
`comment-fingerprint.mjs` reports all 90 codeHash-identical with every
protected count unchanged.

Two defects in the already-merged tools, both found by running them:

**`leafTokens` treated JSDoc as code.** TypeScript hangs a `JSDoc` node off the
declaration it documents and `getChildren()` returns it, so a doc comment
entered the token stream. Every JSDoc edit then looked like it moved the next
comment: collapsing one block reported `// --- Constants ---` below it as
DISPLACED in a file whose code was untouched. Six false positives on one run.
The walk now skips the JSDoc subtree.

**`--repo` refused a relative path.** `createRequire` needs an absolute one, so
`--repo .` threw. Fixed in all three tools.

The sweep rules each earned a guard by damaging something real first, and each
guard is named in its own comment:

- banners are exempt, because a label repeats the identifiers below it — the
  unguarded rule deleted the banners tier 1 had just written
- trailing comments are exempt, because they carry what a literal cannot say
  about itself (`width: 0, // Dimension extraction disabled`)
- only an isolated comment is eligible, because a `//` run is one comment
  wearing several line markers — scoring its last line alone deleted
  `// listing.` off a four-line rationale
- tier 2 takes only a block whose prose is exactly one line, after splitting on
  sentence punctuation joined two facts into a run-on

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@Ardnived
Ardnived merged commit cabd17c into main Sep 16, 2026
3 checks passed
@Ardnived
Ardnived deleted the claude/comment-sweep-tool branch September 16, 2026 19:31
@sydevs-bot sydevs-bot moved this from Revising to Done in SYDevelopers Technical Roadmap Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

1 participant