From 322c7f2a3cfbb9dca50c6549d5f96286f92db8e2 Mon Sep 17 00:00:00 2001
From: jparker2006 <85816763+jparker2006@users.noreply.github.com>
Date: Fri, 20 Nov 2026 16:05:57 +0000
Subject: [PATCH 1/4] #1826: carry the comments contract and checker,
byte-identical to OpenWiz 502b1f32
---
contracts/comments.v1.md | 143 +++++++
tools/comment-check/check.py | 770 +++++++++++++++++++++++++++++++++++
2 files changed, 913 insertions(+)
create mode 100644 contracts/comments.v1.md
create mode 100644 tools/comment-check/check.py
diff --git a/contracts/comments.v1.md b/contracts/comments.v1.md
new file mode 100644
index 0000000..d222f8a
--- /dev/null
+++ b/contracts/comments.v1.md
@@ -0,0 +1,143 @@
+# OpenWiz comments contract, version 1 (`openwiz.comments.v1`)
+
+Which comments stay in our code, how CI keeps new ones out, and how a repository's comment lines are counted, BEFORE and AFTER, the same way everywhere. The checker is [`tools/comment-check/check.py`](../tools/comment-check/check.py) (standard-library Python, one file); the count report's schema is [comments.v1.schema.json](comments.v1.schema.json); the fixtures are in [`fixtures/comments/`](fixtures/comments/), and `tools/comment-check/test_check.py` proves the checker against them.
+
+**Contract and checker first** (#1816, CC1 of spec #1815). Each repository's own ticket (CC2, CC6, CC8, CC9, CC11, CC12) carries a byte-identical copy of this file and the checker and wires the diff mode into its CI; all but CC2 also cut that repository's comments, and CC3 to CC5 cut OpenWiz's by area; CC7 gives review-ticket its comment pass; CC10 draws the count report in the war room.
+
+Authority: spec #1815, from Jake's comment-cut decisions (J238, C1 to C3), 2026-11-19 and 2026-11-20 ([private record](https://github.com/jparker2006/ClosedWiz/issues/3065#issuecomment-7034782715)).
+
+## Words
+
+| Word | Meaning here |
+| --- | --- |
+| **Comment** | Text the language ignores: a line comment, a block comment, a doc comment, or a Python string that stands alone as a statement (a docstring included). Text inside a string literal is never a comment, even when it holds code with comments of its own. |
+| **Comment line** | A line that holds any part of a comment, whole or trailing code. |
+| **Block** | One trailing comment, or a run of whole-line comments on consecutive lines of one kind (doc or not). A multi-line block comment or docstring is one block. The checker judges blocks, never single lines. |
+| **Added line** | A line the pull request adds or changes, from `git diff ...
`. |
+| **Allowed kind** | A block the checker lets in, below. Every other block is disallowed. |
+| **Escape tag** | `comment-ok: `, the one way to keep a block that is none of the allowed kinds. |
+| **Tool directive** | A comment a tool reads to run or build the code. It is code, not a comment. |
+
+## What stays
+
+Only these kinds. The checker reads each one from its form, so the form is the rule: a block that means one of these but lacks its form fails.
+
+| Kind | The form the checker reads | Example |
+| --- | --- | --- |
+| Licence or notice header | `SPDX-License-Identifier:`, `Copyright` or `Licensed under` in a block with no code before it in the file (a shebang or encoding line is not code) | `// SPDX-License-Identifier: MIT` |
+| A constraint from outside our code | The block starts `External:` and holds a link to something that isn't ours (not `github.com/openwizdev/` or `github.com/jparker2006/`) | `# External: the vendor API rounds timeouts down, https://example.com/vendor/issues/7` |
+| Public API docs a published documentation build renders | A doc comment of its own language (Rust `///`, `//!`, `/** */`, `/*! */`; JavaScript and TypeScript `/** */` only; Python's standalone strings, docstrings included; CSS has none) in a path the repository names with `--docs`. A repository with no published documentation build names none | `/// Returns the answer.` under `--docs crates/sdk/` |
+| A security or data-loss warning | The block starts `SECURITY:`, `SAFETY:`, `PRIVACY:` or `DATA LOSS:` and says something after it | `// SAFETY: the buffer outlives every reader.` |
+| A private-record pointer | The block holds a pointer in the [open development contract's form](open-development.v1.md#the-pointer) | `# Private record: https://github.com/jparker2006/ClosedWiz/issues/9001#issuecomment-9000000001` |
+
+The form proves only the shape. Whether the outside constraint is real, the warning true and the docs really published is the reviewer's to judge (CC7's comment pass); a block that wears a form it hasn't earned is a review finding.
+
+## Meaning first
+
+Adapted from pstack's `/no-comments` (Lauren Tan, MIT), in our own words:
+
+1. **When unsure, the comment goes.** Keeping a comment needs a reason from the list above; doubt is not one.
+2. **A surprise in our own code is a refactor, not a comment.** Rename it, extract it, give it a type or write the test that pins it, so the code says it without prose.
+3. **"Important" and "do not remove" are leads, not proof.** Read the code the comment guards and check the claim before keeping or deleting it.
+4. **A constraint comment becomes a check.** If a comment guards a rule (keep this order, never call that first), encode the rule as a type, a test or a CI check, then delete the comment.
+5. **A suppressed correctness lint is a bug to fix.** Remove the suppression and fix the cause; a switch survives only for a style rule or a rule that is wrong for this line, with its reason.
+6. **Nothing that carried meaning is lost.** A comment that told the reader something true becomes a name, a test or a check before it is deleted, and the cut's pull request lists each one; the check or test is red first.
+
+Our addition: private-record pointers and privacy warnings stay, so the open development contract keeps working.
+
+## The escape tag
+
+For the rare real exception none of the kinds covers, a block starts with the tag and its reason:
+
+```text
+# comment-ok: the synthetic runner reads this line as its job name
+```
+
+One form: `comment-ok:` at the start of the block's first line, then a reason of at least one non-space character. `comment-ok:` with nothing after it fails as `escape-tag-reason`. The reason is for the reviewer: a tag whose reason doesn't hold up is a review finding.
+
+## Tool directives are code
+
+These are neither counted nor checked:
+
+- A shebang on line 1 (`#!/usr/bin/env python3`), and a Python encoding line on line 1 or 2 (`# -*- coding: utf-8 -*-`).
+- A lint or formatter switch **with its reason**: the comment starts with one of `noqa`, `type: ignore`, `pragma:`, `pylint:`, `fmt: off|on|skip`, `ruff:`, `mypy:`, `pyright:`, `isort:`, `eslint`, `eslint-disable`, `eslint-enable`, `prettier-ignore`, `@ts-ignore`, `@ts-expect-error`, `@ts-nocheck`, `biome-ignore`, `shellcheck `, `yamllint `, `stylelint-disable`, `stylelint-enable`, `istanbul ignore`, `c8 ignore` or `v8 ignore`, and gives a reason after ` -- ` or a second ` # `, each followed by a space and then the reason: `# shellcheck disable=SC2086 -- word splitting is wanted here`. The same switch without a reason (or with `#reason` and no space) is a comment and fails as `directive-reason`. Only real comments are switches: a Python string that reads like one is a standalone string, counted and judged as a comment.
+- A pinned GitHub Action's version, which update tools read: a line whose only value is a `uses:` field, plain or quoted, `uses: owner/action@<40 hex digits> # v7.0.1`, in a workflow (under `.github/workflows/`) or an action manifest (`action.yml`, `action.yaml`). Elsewhere it is a comment.
+
+Rust's `#[allow(...)]` and `#![allow(...)]` are attributes, not comments: Clippy's `allow_attributes_without_reason` makes each state its reason (CC2).
+
+## What counts as a comment
+
+| Language | Files | Comments | Not comments |
+| --- | --- | --- | --- |
+| Rust | `.rs` | `//`, `///`, `//!`, `/* */` (nested), `/** */`, `/*! */` | strings, raw strings `r#"..."#`, byte and C strings, char literals, lifetimes, attributes |
+| Python | `.py`, `.pyi`, extensionless with a `python` shebang | `#` comments (Python's own tokenizer) and every string that stands alone as a statement (Python's own parser), docstrings included | strings in expressions; a file that doesn't parse is read with the TOML rules |
+| Shell | `.sh`, `.bash`, extensionless with a `sh`, `bash`, `dash` or `zsh` shebang | `#` starting a word (an escaped space doesn't end a word) | quoted text, `$#`, `${#x}`, here-documents (`<<`, never a `<<<` here-string), arithmetic `$(( ))`, `(( ))` and `$[ ]` |
+| YAML | `.yml`, `.yaml` | `#` at a line's start or after a space, outside quotes; the shell rules inside a `run:` block scalar | other block scalars' content; quoted text, including a quoted value that runs over several lines (a quote opens only where a value starts, never inside a plain value) |
+| TOML | `.toml` | `#` outside strings | basic and literal strings; multi-line strings, including a closing run of four or five quotes |
+| JavaScript, TypeScript | `.js`, `.mjs`, `.cjs`, `.jsx`, extensionless with a `node` shebang; `.ts`, `.mts`, `.cts`, `.tsx` | `//`, `/* */`, `/** */` | strings, template literals (with `${}` inside), regular expression literals |
+| CSS | `.css` | `/* */` | strings |
+| HTML | `.html`, `.htm` | `` in text; the CSS rules inside `