Skip to content

feat(functional-clarity): правило комментариев подаётся перед записью - #25

Open
mlopotkov wants to merge 2 commits into
spumer:masterfrom
mlopotkov:master
Open

mlopotkov wants to merge 2 commits into
spumer:masterfrom
mlopotkov:master

Conversation

@mlopotkov

@mlopotkov mlopotkov commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

The norm sat in the context of almost every session and still had to be asked for by hand. The SessionStart hook described it in a paragraph and pointed at references/05-comment-style.md — a path relative to a plugin directory the model cannot resolve, so reaching the norm started with a filesystem-wide search and happened after the review rather than before the write. Subagents never saw the rule at all: SessionStart fires per session, and subagents write most of the code.

The norm now lives in its own skill, comment-style, whose description names the phrasings it must answer to — comment style, cold read, "поправь комментарии" — so the skill loads without being named. The normative text itself is unchanged apart from the enforcement section, which lists three layers instead of two.

The gate text moved to hooks/comment-gate.txt, one source for every consumer. It states when it fires, lists the four forbidden classes one line each, and asks for a self-check before submitting, in place of the descriptive paragraph. The carve-outs for external standards and versioned-API notes are new and account for the roughly 400 characters of added length. The norm's address is substituted from the plugin directory at run time, so it is absolute and opens in one read.

A SubagentStart hook puts the same gate into every subagent's context, with no agent-type matcher: a subagent from any marketplace receives it, and a new writing agent cannot fall out of coverage silently.

The gate stays silent and exits zero whenever its text is unavailable, including a file that does not decode as UTF-8. When python3 is missing the hook does not start at all — otherwise every subagent launch would carry a hook-error notice, noise where the design calls for silence.

Pointers in functional-clarity and in the sdlc skills name the skill instead of the file path.

The plugin version is not bumped — bumping belongs to the release pass.

(cherry picked from commit c638870)

Summary by Sourcery

Make comment guidance available before code changes by promoting it to a dedicated skill and delivering a shared, fail-open gate to sessions and every subagent.

New Features:

  • Deliver the comment-style rule through a dedicated skill and shared pre-write guidance for sessions and all subagents.

Bug Fixes:

  • Prevent unavailable, invalid, or undecodable guidance from producing errors or blocking session and subagent startup.
  • Replace unresolved relative references with skill-based and absolute paths to the normative comment guidance.

Enhancements:

  • Centralize comment-gate text and update functional-clarity and sdlc documentation to reference the dedicated skill.
  • Expand comment-style enforcement to cover session, subagent, and review layers while preserving explicit exceptions for legitimate comments.

Documentation:

  • Document the new comment-style skill, hook delivery behavior, failure-silent guarantees, and updated plugin composition.

Tests:

  • Add coverage for session and subagent guidance delivery, Unicode handling, invalid UTF-8, missing dependencies, malformed input, and silent fallback behavior.

Chores:

  • Record and archive the OpenSpec requirements, design decisions, validation results, and testing limitations for comment-guidance delivery.

@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR replaces a late, path-based comment rule with a dedicated auto-triggered comment-style skill and a shared pre-write gate delivered at session and every subagent start, while preserving fail-open behavior and adding documentation and hook tests.

Sequence diagram for the comment-style pre-write gate

sequenceDiagram
    participant Session as SessionStart
    participant Subagent as SubagentStart
    participant Gate as comment-gate.txt
    participant Agent as Agent
    participant Skill as comment-style
    participant Review as code-reviewer

    Session->>Gate: read gate text
    Gate-->>Session: gate with absolute plugin path
    Session->>Agent: add pre-write self-check
    Subagent->>Gate: read gate text
    Gate-->>Subagent: gate with absolute plugin path
    Subagent->>Agent: add pre-write self-check
    Agent->>Skill: activate on comment-style, cold read, or comment-fix request
    Skill-->>Agent: normative rule and examples
    Agent->>Review: submit changed code
    Review->>Skill: apply comment hygiene rule
Loading

Flow diagram for fail-open SubagentStart behavior

flowchart TD
    Start[SubagentStart] --> Python{python3 available}
    Python -->|no| Silent[exit zero without output]
    Python -->|yes| Read[read comment-gate.txt as UTF-8]
    Read --> Available{file readable and non-empty}
    Available -->|no| Silent
    Available -->|yes| Substitute[substitute absolute plugin path]
    Substitute --> Context[emit additionalContext]
Loading

File-Level Changes

Change Details Files
Moved comment-style guidance into an auto-discoverable dedicated skill and updated all references to use the skill identifier.
  • Added trigger-rich front matter, normative guidance, allowlist, and borderline cases to the new skill.
  • Removed the comment-style reference from the functional-clarity reference set.
  • Updated functional-clarity and sdlc documentation and skills to activate the dedicated skill instead of reading a file path.
plugins/functional-clarity/skills/comment-style/SKILL.md
plugins/functional-clarity/skills/functional-clarity/SKILL.md
plugins/functional-clarity/skills/functional-clarity/references/00-principles.md
plugins/functional-clarity/skills/functional-clarity/references/01-style-guide.md
plugins/sdlc/skills/code-implementer/SKILL.md
plugins/sdlc/skills/code-reviewer/SKILL.md
plugins/sdlc/skills/code-reviewer/references/review-conventions.md
Centralized the pre-write comment gate and injected it into both sessions and subagents with fail-open behavior.
  • Added a shared gate text with firing conditions, forbidden comment classes, self-check instructions, and carve-outs.
  • Changed SessionStart to load the gate from the plugin root and substitute an absolute skill path.
  • Added an unfiltered SubagentStart hook that forwards the gate through additional context to every subagent.
  • Made missing, empty, undecodable, or unavailable gate content silent; documented the Python dependency behavior.
plugins/functional-clarity/hooks/comment-gate.txt
plugins/functional-clarity/hooks/hooks.json
plugins/functional-clarity/hooks/session-start.sh
plugins/functional-clarity/hooks/subagent_comment_gate.py
Expanded plugin documentation and automated coverage for the new comment-style delivery path.
  • Documented the new skill, SessionStart/SubagentStart behavior, component layout, and test commands.
  • Added unit tests for path substitution, valid hook output, and all fail-open cases including malformed input and invalid UTF-8.
  • Updated repository-level documentation to describe the dedicated skill and pre-edit enforcement.
plugins/functional-clarity/hooks/test_subagent_comment_gate.py
plugins/functional-clarity/README.md
docs/plugins/functional-clarity.md
README.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 4 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="plugins/functional-clarity/hooks/subagent_comment_gate.py" line_range="58" />
<code_context>
+            "additionalContext": text,
+        }
+    }
+    print(json.dumps(output, ensure_ascii=False))
+    return 0
+
</code_context>
<issue_to_address>
**Subagent gate fails on legacy encodings**

When a Python runtime's stdout encoding cannot represent the gate text, such as under a legacy locale or code page, `print` serializes the Russian and symbol-containing gate with `ensure_ascii=False`; when stdout uses an encoding that cannot represent those characters, it raises `UnicodeEncodeError` and the SubagentStart hook emits no context. The subagent starts without the rule and the hook reports a failure.

Use ASCII-escaped JSON (omit `ensure_ascii=False`) or explicitly configure stdout for UTF-8 before printing.
</issue_to_address>

### Comment 2
<location path="plugins/functional-clarity/hooks/session-start.sh" line_range="31-32" />
<code_context>
 EOF
+
+if [[ -n "$CLAUDE_PLUGIN_ROOT" ]]; then
+  gate_text="$(cat "${CLAUDE_PLUGIN_ROOT}/hooks/comment-gate.txt" 2>/dev/null)"
+  echo "${gate_text//\{\{PLUGIN_ROOT\}\}/$CLAUDE_PLUGIN_ROOT}"
+fi
</code_context>
<issue_to_address>
**Invalid gate bytes reach session context**

When the gate file contains bytes that are not valid UTF-8, `session-start.sh` stores `cat`'s raw bytes in `gate_text` and `echo` forwards them without validation, so the session receives corrupted gate text or a malformed hook response instead of remaining silent.

Validate the gate text as UTF-8 before echoing it and emit nothing when it is invalid.
</issue_to_address>

### Comment 3
<location path="plugins/functional-clarity/hooks/session-start.sh" line_range="32" />
<code_context>
+
+if [[ -n "$CLAUDE_PLUGIN_ROOT" ]]; then
+  gate_text="$(cat "${CLAUDE_PLUGIN_ROOT}/hooks/comment-gate.txt" 2>/dev/null)"
+  echo "${gate_text//\{\{PLUGIN_ROOT\}\}/$CLAUDE_PLUGIN_ROOT}"
+fi
</code_context>
<issue_to_address>
**Allowed XXX comments are rejected**

When an agent is writing or evaluating an unfinished-work comment using `XXX`, an agent considering an unfinished-work comment marked `XXX` receives a gate that names only `TODO/FIXME` as the accepted format, while the normative skill explicitly allows `XXX` with content. The gate therefore discourages a comment the skill permits.

Add `XXX` with content to the gate's unfinished-work exception so it matches the normative allowlist.

Also at `plugins/functional-clarity/hooks/subagent_comment_gate.py:55`.
</issue_to_address>

### Comment 4
<location path="plugins/functional-clarity/skills/functional-clarity/SKILL.md" line_range="130" />
<code_context>
 - **`references/03-developer-levels.md`** — Developer level definitions (Junior → Senior+)
 - **`references/04-bash-instructions.md`** — Bash script guidelines
 - **`references/frameworks/python.md`** — Python-specific: modern syntax, pathlib, type annotations, pytest patterns
</code_context>
<issue_to_address>
**Comment-style source link is broken**

When a reader follows the comment-style Sources link in the functional-code-clarity spec, the Sources link still targets `plugins/functional-clarity/skills/functional-clarity/references/05-comment-style.md`, which no longer exists after the rule moved to the `comment-style` skill, so readers following the spec get a missing file.

Update the spec link to `plugins/functional-clarity/skills/comment-style/SKILL.md`.
</issue_to_address>

Sourcery assessment

Approval pending. 3 findings to address first.

Blocking findings: plugins/functional-clarity/hooks/subagent_comment_gate.py:58, plugins/functional-clarity/hooks/session-start.sh:32, plugins/functional-clarity/hooks/session-start.sh:32


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

mlopotkov and others added 2 commits October 27, 2026 11:59
The norm sat in the context of almost every session and still had to be asked
for by hand. The SessionStart hook described it in a paragraph and pointed at
references/05-comment-style.md — a path relative to a plugin directory the
model cannot resolve, so reaching the norm started with a filesystem-wide
search and happened after the review rather than before the write. Subagents
never saw the rule at all: SessionStart fires per session, and subagents write
most of the code.

The norm now lives in its own skill, comment-style, whose description names
the phrasings it must answer to — comment style, cold read, "поправь
комментарии" — so the skill loads without being named. The normative text
itself is unchanged apart from the enforcement section, which lists three
layers instead of two.

The gate text moved to hooks/comment-gate.txt, one source for every consumer.
It states when it fires, lists the four forbidden classes one line each, and
asks for a self-check before submitting, in place of the descriptive
paragraph. The carve-outs for external standards and versioned-API notes are
new and account for the roughly 400 characters of added length. The norm's
address is substituted from the plugin directory at run time, so it is
absolute and opens in one read.

A SubagentStart hook puts the same gate into every subagent's context, with no
agent-type matcher: a subagent from any marketplace receives it, and a new
writing agent cannot fall out of coverage silently.

The gate stays silent and exits zero whenever its text is unavailable,
including a file that does not decode as UTF-8. When python3 is missing the
hook does not start at all — otherwise every subagent launch would carry a
hook-error notice, noise where the design calls for silence.

Pointers in functional-clarity and in the sdlc skills name the skill instead
of the file path.

The plugin version is not bumped — bumping belongs to the release pass.

(cherry picked from commit c638870)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Спецификация прежде задавала содержание комментария, но не передачу правила основному агенту и субагентам. Теперь договор доставки отделён от предписаний модели, а завершённое описание изменения сохраняет сценарии отказа, результаты регрессионных проверок и ограничения общей проверки исходного проекта.

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

This branch has not been deployed

No deployments
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