Skip to content

feat(lint): flag Go packages under util and common with an error rule - #202

Merged
furedea merged 11 commits into
mainfrom
feat/check-vague-file-names-with-ast-grep
Nov 15, 2026
Merged

furedea merged 11 commits into
mainfrom
feat/check-vague-file-names-with-ast-grep

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Refs #74

計画:#74 (comment)

概要

static rule は違反時に編集をブロックするため,常に誤りと言える形だけを残す.曖昧な語彙のファイル名(utils.py など)は文脈で正当な場合があるので規則にせず,関連する文章も削除する(復元しない).

  • 規則:go_no_vague_directory_name(rules/go/go_no_vague_directory_name.yml,severity: error).util/,common/ 配下の .go を指摘し,message は誤りの理由(名前から何のパッケージか分からない),note は修正手順(ドメイン名のディレクトリへ移し,import パスを更新する)を述べる.blocking hook(feat(hooks): block edits on static rule errors and guard ast-grep-ignore #203)が両方を表示するため.error の規則に note が無いと失敗するテストも追加した.pkg/ は公式ドキュメントが禁じておらず,polyglot monorepo で有用なので対象にしない(Go Code Review Comments が名指しするのは util / common).files: の glob と rule: {kind: source_file} で判定する.
  • hook の修正(agents/hooks/lib/static_rule_scan.py):files: の glob が repo より上の祖先ディレクトリ(~/common/ など)に一致しないよう,設定ごとの基準ディレクトリ(共有設定は repo root,プロジェクトの sgconfig.yml はその親ディレクトリ)から相対パスで ast-grep を実行する.メッセージ中のパスは従来どおり絶対パス.
  • テスト:ast-grep test のスニペットはパスを持たないため,files: で絞った規則はスニペット要件から外し,一時ツリーを ast-grep scan する別テストで検証する(指摘されるパスと,user_store.go,util.go,pkg/store/user.go,internal/package/user.go など指摘されないパス).祖先に common,pkg,util,tests があっても通常の Go ファイルを指摘しないテスト(hook のコード経由)と,入れ子の sgconfig.yml のテストを追加した.

文章と規則の対応表

規則 ID 元の場所 元の規則(原文) 判定 実装 例のテスト 元の文章
go_no_vague_directory_name go-style/references/tooling.md:17 Do not create pkg/, util/, or common/; name packages by domain. 静的(ast-grep,error) rules/go/go_no_vague_directory_name.yml tests/test_ast_grep_rules.py(パスの一覧) 削除(util / common は規則が置換).「pkg/ は有用なら使ってよい(公式は禁じていない)」の 1 行を追加(pkg/ の禁止は撤回)
(規則なし) python-style/references/code_style.md:37 Avoid utils.py / helpers.py 文章のまま廃止 なし なし 削除(復元しない)
(規則なし) typescript-style/references/tooling.md:28 Avoid utils.ts and helpers.ts 文章のまま廃止 なし なし 削除(復元しない)
(規則なし) rust-style/references/tooling.md:26 Avoid utils.rs and helpers.rs 文章のまま廃止 なし なし 削除(復元しない)
(規則なし) go-style,rust-style,typescript-style の references/code_style.md Avoid manager, helper, util, and common unless the name is already established locally. 文章のまま廃止 なし なし 削除(文ごとすべて削除.Go の util/ と common/ ディレクトリは規則のみで扱う)

現在の hit(修正はこの PR に含めない)

この PR の設定で,読み取りのみで ast-grep scan を実行した.go_no_vague_directory_name(util/,common/)の hit は 3 リポジトリとも 0 件(pkg/ は対象外)(agent-config,agent-harness,dotfiles).

検証

  • uv run pytest: 3888 passed,1 skipped(tests/test_ast_grep_rules.py と tests/hooks.全体は直前の 4861 passed,1 skipped)
  • ruff check,ruff format --check,ty,ls-lint(pre-commit): 通過

フォローアップ(レビュー上限により defer)

  • 非 Nix の scripts/bootstrap_server.sh は ast-grep を入れないため,その環境では ast-grep 規則すべてが届かない(この PR より前からの欠落).

  • .git も sgconfig.yml も無い polyglot project で,go.mod を持つ module の util/ 配下に package.json などが共存すると,hook が util/ 自体を基準にして go_no_vague_directory_name を見逃す.manifest は対象言語のものを優先する必要がある(agents/hooks/lib/static_rule_scan.py の scan_root).

  • Codex の指摘:Python / Rust / TypeScript の utils / helpers 行と manager などの文の削除を戻すべき(対応する規則が無いため).「削除する.復元しない」というユーザーの決定と食い違うため,この PR では戻さず,別 Issue で方針を確認する.

既知の挙動

  • go_no_vague_directory_name は error で,既存の util/,common/ を持つ repo でもその配下の編集ごとに指摘する(util / common は常に誤りとする決定による).

🤖 Generated with Claude Code

… they replace

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

furedea commented Nov 14, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T04:36:39.015131Z 66d640d Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown

Review summary

Blocking findings (P0/P1): 0

  • P2 go_no_vague_file_name.yml:8: the edit hook passes absolute paths to ast-grep scan. As a result, the directory glob **/{pkg,util,common}/**/*.go (and the Rust tests/common ignore) may match ancestor directories above the repo root. The new test scans with relative paths only, so this case isn't covered. ast-grep wasn't available here, so this is unverified; please add a test that uses an absolute path.

Otherwise the rules, the removed prose, and the test changes look correct. I found no security issues.

🤖 Generated with Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 97d55fb95a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

furedea commented Nov 14, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review summary

No blocking findings, and no findings above the reporting bar.

What I checked:

  • static_rule_scan.scan_root: paths reaching the scanner have already been resolved to absolute paths by hook_input.target_paths, so relative_to(root) always succeeds. The nearest .git (a directory or a worktree file) wins over enclosing repositories. Step.cwd is passed through to Popen by process_runner.run_process. Findings are turned back into absolute paths with root / record["file"], so the message format stays the same.
  • Rule globs: the [._-] boundary classes leave utility, futile and user_store alone. tests/common/** (Rust) and dunder files (Python) are excluded as the PR describes. The Go directory rule is matched against repository-relative paths, so ancestor directories such as ~/common/ can't trigger it. The new ancestor-directory test covers this.
  • Tests: rules scoped with files: are taken out of the snippet valid/invalid requirement only, and they get both flagged and clean path fixtures. test_every_file_scoped_rule_has_flagged_and_clean_paths makes sure no future file-scoped rule goes untested.

Not a defect, just a note: a project sgconfig.yml in a subdirectory of a repository now has its files: globs matched against repository-relative paths, where they used to be matched against absolute paths. Neither form matches globs written relative to the project, so nothing regresses.

I couldn't run ast-grep in this environment (it isn't installed), so the scan-based tests weren't executed here.

🤖 Generated with Claude Code

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2887170793

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread agents/hooks/lib/static_rule_scan.py Resolved
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 14, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review summary

No P0–P3 findings.

Checked:

  • static_rule_scan.scan_root / relative_to: both roots (project config dir, or nearest .git / project / file dir for the shared config) are always ancestors of the hook-resolved absolute path, so relative_to cannot raise. Findings are re-anchored to absolute paths via root / record['file'], and failure() threading of root is consistent.
  • Running from cwd=root keeps ancestor directories above the repo (e.g. ~/common/) out of the files: globs; covered by test_directories_above_the_repository_do_not_change_what_the_hook_flags and the per-config base-directory hook test.
  • Rule globs: [._-] separators correctly avoid utility / futile; Python dunder and Rust tests/common/** ignores behave as described; Go directory rule only fires within the repo root.
  • Test changes: file-scoped rules are excluded from snippet-case requirements but are covered by the new named-file scan test, with a guard that every file-scoped rule has flagged and clean paths.

Note (not blocking): the two existing hits in this repo (formatter_policy.py, test_formatter_config.py) will produce advisory warnings on every edit until renamed, as acknowledged in the PR body.

Blocking findings: 0

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 260434987f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

furedea commented Nov 14, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

レビュー結果(Claude)

ブロッキングな指摘はありません(P0: 0,P1: 0,P2: 0,P3: 0).

確認した点:

  • static_rule_scan.scan_root:hook から渡るパスは hook_input で resolve() 済みの絶対パスなので,path.relative_to(root) は常に成り立つ.--config も絶対パスのため,cwd=root に変えても設定ファイルの解決は壊れない.
  • finding は root / record["file"] で絶対パスに戻すので,メッセージの形式は従来と同じ.既存テストとリポジトリ・プロジェクトを分ける新テストで検証されている.
  • 規則の glob(*[._-]utils など)は utility / futile を除外し,__init__.py と Rust の tests/common/ も除外している.ast-grep scan を一時ツリーに対して実行するテストで,指摘されるパスとされないパスの両方を確認している.リポジトリより上のディレクトリ(~/common/ など)が glob に入らないことも別テストで確認している.
  • 指摘の対象外として,リポジトリ外のファイルは path.parent を基準に判定するため,ディレクトリを見る規則(Go の pkg/ や Rust の tests/common/ の除外)はそこでは効かない.頻度が低いため指摘にはしていない.

なお,この環境には ast-grep がないため,ast-grep を実際に動かすテストはここでは実行していない.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9b2e1a83c6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

furedea commented Nov 14, 2026

Copy link
Copy Markdown
Owner

@codex review

@furedea-agent furedea-agent Bot changed the title feat(lint): flag vaguely named files with ast-grep and drop the prose they replace feat(lint): flag Go packages under pkg, util, and common with an error rule Nov 14, 2026
…mmon

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea-agent furedea-agent Bot changed the title feat(lint): flag Go packages under pkg, util, and common with an error rule feat(lint): flag Go packages under util and common with an error rule Nov 14, 2026
@furedea

furedea commented Nov 14, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review summary

Blocking findings: 0 (P0: 0, P1: 0, P2: 1, P3: 0)

  • [P2] go_no_vague_directory_name reports an error on every Go file under an existing util/ or common/ tree. This contradicts the "unless already established locally" exception that go-style/references/code_style.md keeps. Details are in the inline comment.

Checked and looks correct:

  • static_rule_scan.scan_root: hook paths are already resolved to absolute paths (hook_input.target_paths), so relative_to(root) is safe. .git detection also works for worktrees and submodules, where .git is a file. Findings are joined back to absolute paths, and failure output still filters out finding lines.
  • Project configs are scanned from their own directory and the shared config from the repo root. The new hook test covers this, and the ancestor-directory test covers the ~/common/ case.
  • The new path-based tests check both the paths that should be flagged and the ones that shouldn't, including pkg/ and util.go.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d0448cc9df

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…jected

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

furedea commented Nov 14, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 263d909100

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread agents/hooks/lib/static_rule_scan.py Resolved
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 14, 2026

Copy link
Copy Markdown
Owner

@codex review

Comment thread agents/hooks/lib/static_rule_scan.py Resolved
@github-actions

Copy link
Copy Markdown

Review summary

Blocking findings (P0/P1): 0

What I checked:

  • static_rule_scan.scan_root now runs ast-grep from a base directory for each config. The project config uses its own directory. The shared config uses, in order, the repo root, the project sgconfig.yml directory, the nearest manifest, or the file's parent. files: globs are matched against paths relative to that base, so ancestors such as ~/common/ are no longer flagged. relative_to cannot fail, because every root it uses is a lexical parent of the (already absolute) target path. Messages still print absolute paths (root / record['file']).
  • go_error_no_string_matching already used ignores: **/*_test.go, and that pattern behaves the same on relative paths.
  • New tests cover flagged and clean paths, ancestor directories named common/pkg/util/tests, the manifest-only (no git) case, and nested sgconfig.yml base directories.

Finding:

  • P3 (inline): relative filenames that start with - can now be parsed by ast-grep as flags. Fix with -- or a ./ prefix.

I didn't run anything, so the ast-grep scan tests weren't checked here: ast-grep isn't installed in this environment. They depend on how ast-grep matches files: globs against paths given relative to the working directory, and I'm relying on the author's CI result for that.

🤖 Generated with Claude Code

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 34efee1aa5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread agents/hooks/lib/static_rule_scan.py Resolved
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 14, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Automated review summary (read-only)

No P0–P3 findings.

What I checked:

  • scan_root / relative_to: lint_format.target_paths resolves every target to an absolute path. The chosen root is always one of the path's ancestors (the repo with .git, the project sgconfig.yml directory, the manifest directory, or the parent directory), so path.relative_to(root) can't raise. Findings are still reported with absolute paths through root / record['file'].
  • -- before the file list stops file names that start with - from being read as options, and a test covers it.
  • Each project sgconfig.yml is scanned from its own directory, while the shared config uses the repo root, and both have tests.
  • Moving rules scoped with files: out of the snippet-case requirement is covered by the new tests that scan real paths (flagged and clean) and by the ancestor-directory tests.

One caveat: I couldn't run ast-grep in this environment, so I didn't confirm locally that the files: glob is matched relative to the working directory. That relies on the PR's test run with ast-grep present.

🤖 Generated with Claude Code

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 22618cb3c3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…nces

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

furedea commented Nov 14, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review summary (read-only): no findings.

I checked the following:

  • scan_root and relative_to: hook targets are already resolved absolute paths (hook_input.target_paths), and the root is always one of the file's own ancestors, so relative_to cannot raise. --config stays absolute, so changing cwd does not move the config lookup.
  • The existing ignores: **/*_test.go in go_error_no_string_matching still matches root-level files now that paths are relative, because **/ matches zero directories.
  • -- before file arguments prevents option-like file names; there is a test for it.
  • The new rule has path-based tests for flagged and clean paths, plus hook-level tests for ancestor directories, the manifest fallback and a nested sgconfig.yml.

Not verified: I couldn't run the tests here. ast-grep isn't installed, and running pytest needed approval that wasn't granted. The ast-grep glob behavior relies on the PR's own scan tests passing in CI.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 11a454fe03

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

furedea commented Nov 15, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review summary

No P0–P3 findings.

What I checked:

  • static_rule_scan.diagnostics / scan_root: hook targets reach this function as absolute, resolved paths (hook_input.target_paths), and every root is either a parent of the path or the parent of the config. So path.relative_to(root) cannot raise. Reported paths are joined back to root, so messages still show absolute paths.
  • -- before the file list: this blocks option injection from file names like -U.go, and a test covers it.
  • The rule glob **/{util,common}/**/*.go is checked against a real ast-grep scan with both flagged and clean paths. Separate tests cover ancestor directories above the repo, the no-.git manifest fallback, and nested sgconfig.yml base directories. CI sets REQUIRE_AST_GREP=1, so these tests can't be silently skipped.
  • test_blocking_rule_states_its_fix_in_a_note enforces that every error rule has a note.

Known gaps the PR body already lists (no blocking concern):

  • In a polyglot project with no .git, the manifest fallback can miss a match.
  • Directories reached through a submodule or a nearer .git (for example a submodule named common/) are not flagged. This is a false negative, not a false block.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 66d640d3f1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@furedea
furedea merged commit de25e1d into main Nov 15, 2026
27 checks passed
@furedea
furedea deleted the feat/check-vague-file-names-with-ast-grep branch November 15, 2026 05:05
furedea added a commit that referenced this pull request Nov 15, 2026
)

Refs #74(Python レーン)
Refs #196

計画:
#74 (comment)

## 概要

**最終方針(ユーザー決定)**: 静的な ast-grep 規則は linter の error と同じく止める(`severity:
error`).残すのは
`py_no_nonlocal`,`py_no_pytest_asyncio`,`py_async_test_anyio_marker`(`anyio`
を完全一致で判定),`py_no_unittest`,`py_no_unittest_mock`,`py_xfail_requires_strict`,`py_mocker_patch_autospec`,`py_no_staticmethod`,`py_dataclass_slots`,`py_plain_class_slots`
と新規 4
規則.`py_logging_dict_message`,`py_loop_variable_descriptive`,`py_definition_order`,`py_frozen_config_complete`
は規則と例のテストと文章を削除した.`py_no_pytest_asyncio` は `pytest.mark.asyncio` と
`pytest_asyncio` の import だけに絞った.まれな例外は,レビュー済みの suppression コメントで通す.

`python-style` skill の文章規則を 1 規則ずつ棚卸しし,最も安い判定手段へ移した(ADR-0020,ADR-0021).

- 既存 linter(ruff)が既に覆う文章は削除し,対応する規則 ID を表に書いた.
- ast-grep 規則を 8 件追加し,`rule-tests` を各規則に valid / invalid 各 3 件以上付けた.
- jev-lint 規則(`model-rules/python/`)を 7 件追加した.文章は ADR-0021
に従い残す.fixtures,eval の当てはめ,baseline は延期(ユーザー指示).
- 規則で置き換わらない文章,文脈が必要な文章は文章のまま残した.
- 方針(更新): 新しいプロジェクトは `furedea/template-*` からだけ作る.template の `main` で有効な
linter 規則が完全に覆う文章は削除し,規則 ID を表に書く.重複する ast-grep 規則
`py_prefer_strenum`(`UP042` と重複)は規則とテストごと削除した.覆われない部分(例外,理由,直し方)は残す.

共有ファイルの変更は `tests/test_model_rule_files.py` だけ(Python の比較を `RULE_IDS` の
3 件に限る変更と,新しい 7 件の subject 数を固定するテスト
`test_python_style_model_rules_select_the_subjects_they_ask_about`
の追加).`test_python_rules_select_the_functions_they_ask_about` が Python
の規則 3 件の subject 数を完全一致で比較していたため,新しい Python 規則が別の
subject(fixture,import,値オブジェクトなど)を選ぶと失敗する.比較を既存の `RULE_IDS` の 3
件に限った.他レーンが同じ関数を編集した場合は,マージ時に同じ方針で解消する.

## 文章と規則の対応表

「元の場所」は `agents/skills/python-style/` からの相対パス.ast-grep の実装は
`agents/hooks/lint/rules/python/`,例のテストは
`agents/hooks/lint/rule-tests/`,jev-lint の実装は
`agents/hooks/lint/model-rules/python/<id>/rule.yml`.

| 規則 ID | 元の場所 | 元の規則(原文) | 判定 | 実装 | 例のテスト | 元の文章 |
| --- | --- | --- | --- | --- | --- | --- |
| `py_no_nonlocal` | references/code_style.md(Functions) | Don't use
`global`, `nonlocal` | 静的(ast-grep).`global` は既存 linter(ruff `PLW0603`)
| `py_no_nonlocal.yml` | 良 2 / 悪 2 | 削除(`nonlocal` は本規則,`global` は
template-python の ruff `PLW0603` が置換) |
| ruff `UP006` / `UP035` | references/code_style.md(Functions) | Use
built-in generics instead of `typing.Tuple`, `typing.List`,
`typing.Dict` | 既存 linter(template-python の ruff
`UP006`,`UP035`.template-python は `UP` を選択済み) | なし | なし |
削除(template-python で有効な規則が完全に覆う) |
| `py_logging_dict_message`(削除)/ `py_no_structlog_loguru`(新規) |
references/code_style.md(Logging) | Write in dictionary format |
辞書形式の規則は削除.標準 `logging` と `extra` を使う方針に変え,structlog と loguru の import
を禁止する静的規則(ast-grep,error)を追加 | `py_no_structlog_loguru.yml` | 良 3 / 悪 5
| 辞書形式の文章と例を削除.Logging の節を 3 項目(十分なログ,handler と formatter は entry point
だけ,`extra` を出す formatter)に書き直した.ruff
`G001`〜`G004`,`G101`,`G201`,`G202`,`LOG002`,`LOG015`,`TRY400` が覆う内容は書かない
|
| `py_loop_variable_descriptive`(削除) | references/code_style.md(Naming)
| Loop body ≥ 3 lines: descriptive name | 規則を削除(名前の良し悪しを形から推測する) | なし |
なし | 削除(Iterator arguments の 2 項目とも) |
| ruff `N801` / `N802` / `N803` / `N806` / `N999` |
references/code_style.md(Naming) | Variables / functions / files:
`snake_case`; Classes: `UpperCamelCase` | 既存 linter(template-python の
ruff `N`) | なし | なし | 削除(template-python で有効な規則が完全に覆う).「Getters:
出力変数の名前」は残る |
| (なし) | references/code_style.md(Naming) | Constants:
`SCREAMING_SNAKE_CASE` … module-level constants (two blank lines after
imports) | 文章のまま | なし | なし | 残す(ruff `N` は定数の大文字を判定しない.意味のある文字列の定数化は下の
`string-literal-is-named-constant` が判定し,文章も残す) |
| `string-literal-is-named-constant` | references/code_style.md(Naming)
| define semantically meaningful string literals as module-level
constants rather than embedding them inline | 動的(jev-lint,0.5) |
`model-rules/python/string-literal-is-named-constant/rule.yml` | 延期 |
残して併記(ADR-0021) |
| (なし) | references/code_style.md(Naming / Iterator arguments) | Loop
body ≤ 2 lines: single character | 文章のまま | なし | なし |
残す(許可であり,違反を構文で定義できない) |
| (なし) | references/code_style.md(File Naming) | Name files after the
domain/action, not the role suffix; `-er`/`-or` belong on class names |
文章のまま | なし | なし | 残す(語の意味の判断で,ls-lint の正規表現(RE2)で書けない) |
| (なし) | references/code_style.md(File Naming) | Avoid `utils.py` /
`helpers.py` | 文章のまま | なし | なし | 残す(ls-lint
の正規表現(RE2)には否定先読みがなく,template-python の `.ls-lint.yml` では書けない) |
| (なし) | references/code_style.md(Functions) | Keep functions focused
and small | 文章のまま | なし | なし | 残す(単一責務は `agents/AGENTS.md`
の言語非依存の規則が持つ.ruff `C901`,`PLR0912`,`PLR0915` が大きさを一部覆う) |
| (なし) | references/code_style.md(Functions) | Use Pythonic syntax
(comprehensions, `with` statements, etc.) | 文章のまま | なし | なし | 残す(ruff
`C4`,`PERF`,`FURB` が一部を覆うが,全体は判定できない) |
| (なし) | references/code_style.md(Formatting) | Let `ruff format` decide
quotes and operator spacing | 既存 linter(ruff format)への指示 | なし | なし |
残す(ツールの使い方の指示) |
| ruff `I001` / `E301` / `E302` / `E305` |
references/code_style.md(Whitespace) | Two blank lines before/after
object (class/function) definitions; one blank line between instance
methods and between import groups; Imports: standard library →
third-party → local with one blank line | 既存 linter(template-python の
ruff `I001`,`E30x`) | なし | なし | 削除(template-python で有効な規則が完全に覆う) |
| ruff isort `lines-after-imports = 2` |
references/code_style.md(Whitespace) | Two blank lines before/after
import statements and global variable definitions | 既存
linter(template-python の `lines-after-imports = 2`).グローバル変数は文章のまま | なし |
なし | import の行を削除.「グローバル変数の前後 2 行」は ruff に規則がないので残す |
| (なし) | references/code_style.md(Whitespace) | One blank line between
docstring sections | 文章のまま | なし | なし | 残す(ruff `D2xx` が一部を覆う.`D412` /
`D413` は google 規約で無効) |
| `import-name-self-explanatory` | references/code_style.md(Imports) |
Avoid `from ... import ...` unless the name is self-explanatory; avoid
`as` aliases unless required for clarity | 動的(jev-lint,0.5) |
`model-rules/python/import-name-self-explanatory/rule.yml` | 延期 |
残して併記(ADR-0021) |
| (なし) | references/code_style.md(Indentation) | When handling multiple
objects in parallel, align indentation with the previous element | 文章のまま
| なし | なし | 残す(`ruff format` が決める書式で,規則の対象外) |
| (なし) | references/code_style.md(Line Breaks) | One element per line
for lists/dicts with 3+ items or long expressions; trailing comma |
文章のまま(ast-grep は不採用) | なし | なし | 残す(3 要素以上の 1 行リテラルを ast-grep で試すと
agent-config で 498 件,中央値 50 文字の短い定数が大半で,誤検出が多すぎた.`ruff format` の magic
trailing comma と `E501` が長い式を覆う) |
| (なし) | references/code_style.md(Line Breaks) | Don't sacrifice
readability for brevity | 文章のまま | なし | なし | 残す(判断の指針) |
| (なし) | references/code_style.md(Comments & Docstrings) | Write
comments on their own line above the relevant code | 文章のまま | なし | なし |
残す(行末コメントは ast-grep が行の位置を比較できず,ruff にも禁止規則がない) |
| ruff `D100` / `D101` / `D102` / `D103` |
references/code_style.md(Comments & Docstrings) | Always add docstrings
to public APIs | 既存 linter(template-python の ruff `D`,google 規約.`D104` /
`D105` / `D107` は template が無効) | なし | なし | 削除(template-python
で有効な規則が完全に覆う) |
| (なし) | references/code_style.md(Comments & Docstrings) | Comment
non-obvious choices (algorithm params, fallback behavior, encoding
handling) | 文章のまま | なし | なし | 残す(何が自明でないかは文脈の判断.コメント最小化は
`agents/AGENTS.md` が持つ) |
| ruff `DOC201` / `DOC402` / `DOC501` / `D417` |
references/code_style.md(Comments & Docstrings の例) | Docstring layout
(summary, details, `Args`, `Returns/Yields`, `Raises`) | 既存
linter(template-python の `DOC201`,`DOC402`,`DOC501`,`D417`) | なし | なし |
残す(節の並びと空行,例の書式は規則が覆わない.節の有無は linter が判定する) |
| `py_definition_order`(削除) | references/models.md(Classes) | prefer
`Enum -> model/class -> function` ordering | 規則を削除(従うと `NameError`
になる例外を判別できない) | なし | なし | 削除 |
| `plain-class-defines-slots`(`py_plain_class_slots` から降格) |
references/models.md(Classes) | Use `__slots__` to restrict variables
when not using `dataclasses` or `pydantic` |
動的(jev-lint,advisory,0.5).ast-grep
規則はレビューが収束しない(基底,デコレータ,`cached_property` の書き方が多い)ため削除 |
`model-rules/python/plain-class-defines-slots/rule.yml` | 延期 |
残して併記(ADR-0021) |
| `py_dataclass_slots` | references/models.md(Value Objects) |
`dataclasses.dataclass(frozen=True, slots=True)` | 静的(ast-grep,既存) |
`py_dataclass_slots.yml`(既存) | 既存 | 変更なし |
| `value-object-is-immutable` | references/models.md(Value Objects) |
Value Objects: `pydantic.BaseModel` or `dataclass(frozen=True,
slots=True)` | 動的(jev-lint,0.5) |
`model-rules/python/value-object-is-immutable/rule.yml` | 延期 |
残して併記(ADR-0021).値オブジェクトかどうかは構文から判別できないので,`py_dataclass_slots` の note
と合わせてモデルに任せた |
| (なし) | references/models.md(Value Objects) | Resolve routine
representation choices from existing dependencies and nearby code; ask
only when a material decision is not covered | 文章のまま | なし | なし |
残す(進め方の指示) |
| (なし) | references/models.md(Value Objects) | Use `__post_init__` to
enforce invariants | 文章のまま | なし | なし |
残す(不変条件の有無は構文から判別できない.`agents/AGENTS.md` の Value Object の規則が持つ) |
| `construction-placement-by-purity` | references/models.md(Value
Objects) | Use classmethods as alternative constructors for pure
construction; if construction involves I/O, a module-level function |
動的(jev-lint,0.5) |
`model-rules/python/construction-placement-by-purity/rule.yml` | 延期 |
残して併記(ADR-0021) |
| `py_pydantic_base_model_only_in_frozen_base` /
`py_frozen_base_model_config` / `py_frozen_base_model_no_override` |
references/models.md(Pydantic) | Frozen model config:
`ConfigDict(extra="forbid", frozen=True, strict=True,
validate_default=True)` / shared base class |
静的(ast-grep,error).`BaseModel` を直接継承できるのは `FrozenBaseModel` だけ,その
`model_config` は 5 キー(`revalidate_instances="always"` を追加)を持つ,サブクラスは 5
キーを上書きしない |
`py_pydantic_base_model_only_in_frozen_base.yml`,`py_frozen_base_model_config.yml`,`py_frozen_base_model_no_override.yml`
| 良 5 / 悪 4,良 3 / 悪 3,良 4 / 悪 4 | 削除して書き直し(`FrozenBaseModel`
の例と,pydantic は境界だけという 1 行に置換.旧 `py_frozen_config_complete` は削除) |
| `json-parse-uses-model-validate-json`(`py_pydantic_validate_json`
から降格) | references/models.md(Pydantic) | JSON は `model_validate_json`
で読む | 動的(jev-lint,advisory,0.5).データフロー(変数経由,変更の有無)を ast-grep
では判定できないため,ast-grep 規則を削除 |
`model-rules/python/json-parse-uses-model-validate-json/rule.yml` | 延期 |
文章は残す(pydantic の節の 1 文) |
| (なし) | references/models.md(Pydantic) | When multiple frozen models
exist, extract a shared base class to `base.py` | 文章のまま | なし | なし |
残す(複数ファイルにまたがる重複の判断で,1 ファイルの構文から判別できない) |
| `fixed-choices-use-enum` | references/models.md(Enums) | Use
`Enum`/`StrEnum` for fixed choices instead of raw string literals or
dict maps | 動的(jev-lint,0.5) |
`model-rules/python/fixed-choices-use-enum/rule.yml` | 延期 |
残して併記(ADR-0021) |
| (なし) | references/models.md(Enums) | Convert user input strings to
Enum early, then map through Enum values | 文章のまま | なし | なし |
残す(境界での変換の位置は `agents/AGENTS.md` の「境界で 1 回だけ型に変換する」規則が持つ) |
| ruff `UP042` | references/models.md(Enums) | Prefer `StrEnum` when
values are serialized or user-facing | 既存 linter(template-python の
`UP042`.`(str, Enum)` の混在を覆う.重複する ast-grep 規則 `py_prefer_strenum` は削除) |
なし | なし | 残す(直列化や表示の有無で `Enum` と `StrEnum` を選ぶ判断は規則が覆わない) |
| `py_no_unittest` | references/testing.md | Use `pytest` as test
framework | 静的(ast-grep,既存) | `py_no_unittest.yml`(既存) | 既存 |
変更なし(「pytest を使う」の指示は残る) |
| (なし) | references/testing.md | Run tests using `uv run --frozen
pytest` | 文章のまま | なし | なし | 残す(コマンドの指示.`forbidden_commands.json`
は一部のバイパスしか覆わない) |
| `py_no_pytest_asyncio` | references/testing.md | Use `anyio` for async
tests, do not use `asyncio` | 静的(ast-grep) |
`py_no_pytest_asyncio.yml`(`pytest.mark.asyncio` と `pytest_asyncio` の
import だけを判定.別名の枝は削除) | 良 3 / 悪 4 | 残す(規則は pytest-asyncio の marker と
import だけを判定し,`asyncio` 全般は覆わない) |
| `py_async_test_anyio_marker`(削除) | references/testing.md(Async test
pattern) | `@pytest.mark.anyio` on async tests | 規則を削除.pytest 9.0.3
は,どのプラグインも実行しない async test を失敗にする(使い捨てテストで確認: `async def functions are
not natively supported`).黙って成功しないので規則は不要 | なし | なし | 残す(`anyio_backend`
fixture の書き方の例) |
| `py_no_unittest_mock` | references/testing.md | Use `pytest-mock` for
mocking (`mocker` fixture) | 静的(ast-grep,既存) |
`py_no_unittest_mock.yml`(既存) | 既存 | 変更なし(「mocker を使う」の指示は残る) |
| `py_mocker_patch_autospec` | references/testing.md | (autospec) |
静的(ast-grep,既存) | `py_mocker_patch_autospec.yml`(既存) | 既存 | 変更なし |
| (なし) | references/testing.md | `pytest`, `anyio`, and `pytest-mock`
belong in the template's test dependency group | 文章のまま | なし | なし |
残す(`pyproject.toml` の内容で,Python の構文ではない.依存の検査は deptry の領域) |
| `py_xfail_requires_strict` | references/testing.md | Record a
reproduced defect with `@pytest.mark.xfail(strict=True, reason="...")` |
静的(ast-grep,既存) | `py_xfail_requires_strict.yml`(既存) | 既存 | 変更なし |
| `known-defect-marker-names-removal` | references/testing.md | …and a
comment naming the condition for removing the marker |
動的(jev-lint,既存,0.5) |
`model-rules/python/known-defect-marker-names-removal/rule.yml`(既存) | 既存
| 変更なし |
| (なし) | references/testing.md | Remove the marker in the change that
fixes the defect | 文章のまま | なし | なし | 残す(変更の進め方.差分の文脈が要る) |
| (なし) | references/testing.md(Mutation Testing) | Use `mutmut` (3.x)
when `tsdd` calls for it; `[tool.mutmut]` config; scope a run; list
survivors; keep `mutants/` out of version control | 文章のまま | なし | なし |
残す(ツールの使い方と設定.`.gitignore` と `pyproject.toml` の内容) |
| (なし) | references/testing.md(Test Structure) | Function-based by
default; class only for namespace grouping or
`setup_method`/`teardown_method` | 文章のまま | なし | なし | 残す(namespace のための
class を許すので,違反を構文で定義できない) |
| `fixture-justified` | references/testing.md(Test Structure) |
`@pytest.fixture`: shared setup across 2+ tests, external resources, or
teardown; helper function when arguments are needed or setup is light;
fixture scope default `function` | 動的(jev-lint,0.5) |
`model-rules/python/fixture-justified/rule.yml` | 延期 | 残して併記(ADR-0021) |
| `repeated-tests-use-parametrize` | references/testing.md(Test
Structure) | `@pytest.mark.parametrize`: same logic with different
inputs | 動的(jev-lint,0.5) |
`model-rules/python/repeated-tests-use-parametrize/rule.yml` | 延期 |
残して併記(ADR-0021) |
| (なし) | references/tooling.md(Package Management) | Use only `uv`,
don't use `pip`; `uv sync`; `uv run --frozen {tool}`; `uv add`; `uv add
--group`; `uv lock --upgrade-package`; prohibited `uv pip install`, `uv
add --dev`, `@latest` | 文章のまま | なし | なし |
残す(シェルコマンドの規則.`agents/hooks/rules/forbidden_commands.json` は `python -m
pip` だけを覆う.hook の規則の追加はこの PR の範囲外.ast-grep は Python の構文だけを見る) |
| (なし) | references/tooling.md(Package Management) | Baseline tooling
dependencies belong in template-defined dependency groups | 文章のまま | なし |
なし | 残す(`pyproject.toml` の内容) |
| (なし) | references/tooling.md(Directory Structure) | `./src` for
production code, `./tests` for tests; flat module placement for apps;
`src/<package_name>/` only for distributable packages | 文章のまま | なし | なし
| 残す(設計判断.ディレクトリの構成は ls-lint の対象外) |
| ruff `E501` | references/tooling.md(File Standards) | Keep code within
119 characters per line (URLs may exceed this limit) | 既存
linter(template-python の ruff `E501`,`line-length = 119`.URL だけの行は除外される)
| なし | なし | 削除(template-python で有効な規則が完全に覆う) |
| ruff `ANN001` / `ANN002` / `ANN003` / `ANN201` / `ANN202` / `ANN204` |
references/tooling.md(File Standards) | Always include type hints | 既存
linter(template-python の ruff `ANN`.`main` の `ignore` に `ANN401` は無い) |
なし | なし | 削除(template-python で有効な規則が完全に覆う) |
| (なし) | references/tooling.md(File Standards / Static Type Checking) |
Use ty for static type checking; run `uv run --frozen ty check`; do not
introduce another type checker | 文章のまま | なし | なし | 残す(ツールの選択とコマンド.ty 自体は
template の `typecheck` グループが持つ) |
| (なし) | SKILL.md(Scope) | Scope: code inside a bootstrapped project;
setup belongs to `project-setup`; routine edits do not authorize Nix or
GitHub changes | 文章のまま | なし | なし | 残す(skill の適用範囲と権限の境界) |
| (なし) | SKILL.md(Task-Specific References) | Read only the references
relevant to the current task | 文章のまま | なし | なし | 残す(進め方の指示) |

## 判定に使った設定

- ruff は template-python の `pyproject.toml`(`select` に
`ANN`,`D`,`E`,`I`,`N`,`PLW`,`UP` などを含む)を `gh api` で確認した.ruff は dev shell
にないため規則 ID はローカルで実行せず,ruff の文書上の規則名で対応させた.template repo は変更していない.
- jev-lint の規則は advisory(ADR-0021).Stop の共通 gate は未判定の入力の指摘を 1
回だけ報告して止める(既存の未当てはめ規則と同じ挙動で,hook の変更はこのレーンの範囲外).`threshold:
0.5`,`severity: warning`.

## 波 2: linter で有効化する規則

なし.先に挙げた `lines-after-imports = 2`,`DOC201` / `DOC402` /
`DOC501`,`UP042` は template-python(#26)の `main` で有効なことを確認した.

## 現在の hit(修正はこの PR に含めない)

ローカル checkout に `ast-grep scan --config agents/hooks/lint/sgconfig.yml
.` を読み取りのみで実行した(新しい Python 規則の分).

| repo | 規則 | hit | 場所 |
| --- | --- | --- | --- |
| agent-config | `py_plain_class_slots` | 6 |
scripts/replay_commands.py:174,agents/hooks/lib/shell_paths.py:101,agents/hooks/lib/provider_adapter.py:92,tests/skills/test_skill_commands.py:68,tests/hooks/test_trusted_owners_fallback.py:45,tests/hooks/test_static_rules.py:27
|
| agent-config | `py_no_nonlocal` | 1 |
agents/hooks/lib/check_execution.py:138 |
| agent-config | その他の新規則 | 0 | なし |
| agent-harness | 新規則すべて | 0 | Python の対象がほぼない |
| dotfiles | 新規則すべて | 0 | なし |

`py_multiline_collection`(不採用)は同じ方法で agent-config 498 件,dotfiles 89 件の
hit があった.

## 検証

- `nix develop --command uv run --frozen pytest
tests/test_ast_grep_rules.py tests/test_model_rule_files.py -q`: 55
passed
- `nix develop --command ast-grep test --config
agents/hooks/lint/sgconfig.yml --skip-snapshot-tests`: 全規則 pass
- `jev-lint rules --no-config -R agents/hooks/lint/model-rules/python`:
10 rule(s) loaded, 0 error(s)
- jev-lint の dry-run で,7 件の matcher が想定した subject を選ぶことを確認した(モデルの判定は延期)
- `ruff check` / `ruff format --check`(tests): pass
- 全テスト: `nix develop --command uv run --frozen pytest -q`: 4874 passed,
1 skipped

🤖 Generated with [Claude Code](https://claude.com/claude-code)


追加で,Stop の subject 上限を圧迫しないよう広い jev-lint 規則の
matcher(import,文字列,固定選択肢)を絞った(#192 のレビュー対応).

## 後続へ回した指摘(最終方針対応のレビュー上限)

最終方針対応の 3 回目の再レビューが挙げた次の 3 件は修正せず,"Deferred to a follow-up Issue (review
limit)." と返信して解決した.

- `rules/python/py_async_test_anyio_marker.yml`: 関数名だけで判定し `files:`
の制限がないため,本番コードの `async def test_connection(...)` にも error を出す.`files:`
をテストファイル(`test_*.py`,`*_test.py`,`conftest.py`)に絞る.
- `rules/python/py_async_test_anyio_marker.yml`: `import pytest as pt`
の別名を,クラス直下の `pytestmark = pt.mark.anyio` とリスト要素 `pytestmark =
[pt.mark.anyio]` にも適用する.
- `rules/python/py_frozen_base_model_config.yml`: クラス本体に `model_config`
の代入が複数ある場合,最後の代入が完全かどうかを検査する.
- 参考(修正しなかったと返信して解決):
間接サブクラスの上書きは単一ファイルの構文では解決できない.`py_no_pytest_asyncio` の別名は,ユーザー決定により
`pytest.mark.asyncio` と `pytest_asyncio` の import だけを判定する.

## 後続へ回した指摘(ログ規則追加後のレビュー上限)

次の 4 件は未修正(検出漏れで,誤検出ではない).

- `py_pydantic_validate_json`: `data = None; data = json.loads(...)`
のように loader 代入より前の初期化があると報告しない(検出漏れ).
- `py_pydantic_validate_json`: `json` が標準ライブラリでなく独自オブジェクトのとき(`import
json` に結び付けていない)も報告する.
- `py_async_test_anyio_marker`: `anyio_backend` を別の fixture(`client` や
autouse)経由で使う async test は,fixture
の依存関係を単一ファイルの構文では解決できないため,まだ未マークとして報告する.
- `py_frozen_base_model_no_override`: `ConfigDict(**{"frozen": False})`
のように展開した辞書を `bad_pair` で検査しない.

## 誤検出の修正(ユーザー許可,10ba684)

blocking にする前の誤検出として,次の 3 件を failing な valid 例を先に足してから直した.

- [x] `py_pydantic_validate_json`(決定変更): loader に追加引数があっても報告し続ける.同じ関数で
`$D = json.loads(...)`(別名,`from json import loads [as x]`,orjson,ujson
を含む)として代入した変数を `model_validate($D)` に渡す形も報告する(ast-grep が関係をまたいで `$D`
を束ねることをテストで確認).`json.loads` だけで `model_validate` に渡さない場合は報告しない.
- [x] `py_plain_class_slots` / `py_dataclass_slots`: `cached_property`
の別名の除外が,デコレータ付きクラスとネストしたクラスでも効く.
- [x] `py_async_test_anyio_marker`: `from pytest import mark` がある場合の
bare `@mark.usefixtures("anyio_backend")` / `@mark.anyio`,`pytestmark =
[pytest.mark.usefixtures("anyio_backend"), ...]` と `[pytest.mark.anyio,
...]` のリスト形式を受け入れる.

## blocking の message と note

ブロックする全規則に,なぜ誤りか(`message`)と,そのまま適用できる直し方(`note`,before/after)を書いた.

`py_async_test_anyio_marker` は
`files:`(`test_*.py`,`*_test.py`,`conftest.py`)に限定した.


## main 取り込み後の対応

- `test` が失敗した原因: main の #202 が「`files:` で絞った規則はすべて flagged / clean
のパスを持つ」テストを足し,`py_async_test_anyio_marker` が対象になった.main
を取り込み,`tests/test_ast_grep_rules.py` にこの規則のパスを追加した(全テスト 4921 passed).
- `py_pydantic_validate_json`(誤検出,修正済み): loader
代入を探す関数を呼び出しに最も近い関数に限った.外側で `data = json.loads(...)`,内側の関数が別の `data`
引数を検証する形を報告しない(valid 例を追加).
- 後続へ回した指摘(未修正,検出漏れ): `py_plain_class_slots` は `__slots__ =
("__dict__",)` を有効扱いする.#196 のコメントに追記した.
- 後続へ回した指摘(未修正): `py_pydantic_base_model_only_in_frozen_base` は
`pydantic.v1.BaseModel` を検出しない(検出漏れ).`fixture-justified`
は基準の文言が衝突している(advisory).どちらも #196 のコメントに追記した.
- 誤検出の修正(8bb159c): `py_async_test_anyio_marker` は,別名 `pytest` の
`usefixtures('anyio_backend')`(単引用符)も受け入れる.`conftest.py`
は対象から外し,`py_pydantic_validate_json` は loader
代入が検証より前にある場合だけ一致する(f8207ea).
- 後続へ回した指摘(未修正,検出漏れ): `py_pydantic_validate_json` は複数名 import(`from json
import dumps, loads as x`)の別名を追跡しない.#196 のコメントに追記した.
- 誤検出の修正(b402713,d5931b5): 別名 `pytest` の
`pytestmark`(`usefixtures("anyio_backend")`,クラス直下の `mark.anyio`)も受け入れる.
- 後続へ回した指摘(未修正,検出漏れ): 別名の分岐は receiver を厳密に別名へ結び付けていない.#196 のコメントに追記した.
- 誤検出の修正(0ea63c6): 別名 `pytest` のモジュール直下 `pytestmark` リスト,`from functools
import lru_cache, cached_property as x` の複数名 import(`py_dataclass_slots`
と `py_plain_class_slots`)を受け入れる.
- 誤検出の修正(04fc613): `py_pydantic_validate_json` は,無条件の先行代入だけを loader
代入として扱う(`if` の中の代入は対象外).note には `strict=False`
などの呼び出しオプションを保つ直し方も書いた(7cf166b).
- 後続へ回した指摘(未修正,検出漏れ): `py_plain_class_slots` は `class User():` と `class
User(object):` を継承ありとして除外する.#196 のコメントに追記した.
- 誤検出の修正(2ba6e0b): `py_frozen_base_model_config` は,5 設定がクラスのキーワードと
`model_config` に分かれていても合わせて判定する.`py_async_test_anyio_marker` は `from
pytest import mark as x` の別名も受け入れる.
- 誤検出の修正(bccac41): `py_pydantic_validate_json` は `from json import loads
as x` を素の `loads` とみなさない.
- 後続へ回した指摘(未修正): `anyio_mode = "auto"` のプロジェクトでは
`py_async_test_anyio_marker` が誤検出になる.pytest
設定を単一ファイルの規則から読めないため規則内では直せない.#196 のコメントに追記した.

## 不安定な規則の整理(上の履歴より新しい)

レビューが収束しなかった次の ast-grep 規則を削除した.上のレビュー対応の記述のうち,これらの規則に関するものは古い.

- `py_async_test_anyio_marker`: 削除.pytest 9.0.3 では,マーカーなしの async test
は失敗する(`pytest==9.0.3` と `anyio` で使い捨てテストを実行して確認).
- `py_pydantic_validate_json` → jev-lint
`json-parse-uses-model-validate-json`,`py_plain_class_slots` → jev-lint
`plain-class-defines-slots`(advisory,`threshold:
0.5`,当てはめは延期).規則テストと,これらの規則に関する #196 の後続項目は不要になった.
- 全テスト: 4913 passed, 1 skipped.

## ast-grep から外した規則と理由

ブロックする規則は安定していなければならない.次の規則はレビューのたびに新しい指摘が出て収束しなかったため,既存のツールに任せるか
jev-lint へ降格することをユーザーが決めた.判断の基準は ADR-0021 に記録する.

| 規則 | 行き先 | review の指摘数 | 不安定の型 | 例 |
| --- | --- | --- | --- | --- |
| `py_async_test_anyio_marker` | 削除.pytest 9.0.3 が,どのプラグインも実行しない async
test を失敗にする(使い捨てテストで確認) | 34 | 1) ファイルの外の情報が要る(`anyio_mode = "auto"` は
pytest 設定,`anyio_backend` の使用は fixture の依存関係や `conftest.py`)<br>4)
同じ意味の書き方が多い(`pytestmark` のリストとクラス直下,別名 import,単引用符,`usefixtures` の引数位置)
| 誤検出: `@pt.mark.usefixtures('anyio_backend')`,`from pytest import mark
as m`,`class Helper:` 内の `async def test_x`.検出漏れ: `anyio_backend` を別の
fixture 経由で使う |
| `py_pydantic_validate_json` | jev-lint
`json-parse-uses-model-validate-json` | 17 | 2)
データの流れや実行の順番を追う必要がある(変数に代入してから検証,代入の前後,条件付き代入,検証前の変更)<br>4)
同じ意味の書き方が多い(`json.loads`,別名 import,複数名 import,`orjson`,`ujson`) | 誤検出:
`data["id"] = request_id` の後の `Order.model_validate(data)`.検出漏れ: `from
json import dumps, loads as decode_json` の `decode_json(raw)` |
| `py_plain_class_slots` | jev-lint `plain-class-defines-slots` | 11 |
4) 同じ意味の書き方が多い(基底クラス,デコレータ,`cached_property` の別名,`class User():`)<br>2)
データの流れや実行の順番を追う必要がある(`__init__` の代入先) | 誤検出: `from functools import
lru_cache, cached_property as cached` を使うクラス.検出漏れ: `__slots__ =
("__dict__",)`,`class User(object):` |
| `py_frozen_base_model_no_override` | jev-lint
`frozen-model-subclass-keeps-locked-settings` | 4 | 2)
データの流れや実行の順番を追う必要がある(クラスの継承を複数のクラスやファイルにまたがって追う)<br>4)
同じ意味の書き方が多い(クラスキーワード,`model_config` の `ConfigDict` と辞書) | 検出漏れ: `class
Money(FrozenBaseModel)` の後の `class MutableMoney(Money,
strict=False)`.誤検出: 5 設定がクラスキーワードと `model_config` に分かれた定義 |
| `py_frozen_base_model_config` | jev-lint
`frozen-base-model-sets-all-settings` | 8 | 2)
データの流れや実行の順番を追う必要がある(名前付きの設定定数,`model_config` の再代入)<br>4)
同じ意味の書き方が多い(クラスキーワード,`ConfigDict` と辞書,分割した定義) | 誤検出: `model_config =
COMPLETE_CONFIG`(定数に 5 設定が入っている).検出漏れ: `model_config` を再代入して設定を失う |

指摘数は,この PR のレビュースレッドのうち,規則ファイルのパスに付いたものの数.
`json-parse-uses-model-validate-json` の基準は,`object_hook` や `parse_float`
などの変換オプション付きの `json.loads` を `model_validate_json` と同等とみなさない.

---------

Co-authored-by: furedea <132188853+furedea@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
furedea added a commit that referenced this pull request Nov 16, 2026
…ore (#203)

Refs #74


計画:#74 (comment)

## マージ順序

言語ごとの規則の PR(#190〜#195)と #202 はすべてマージ済み.この PR は origin/main(1919b066)に
rebase してある.main にある `severity: error` の規則 28 件は,すべて規則テストの対象で,`note`
を持っている.追加した note は無い.

この PR が入ると,`severity: error` の static rule はすべて編集をブロックする.また,error の規則には
`note`(修正方法)が必須になる.

### rebase で解決したコンフリクト

- 1 回目(#190,#202,#205,#208 の後):ブランチのコミットごとに同じ関数で衝突したため,1 コミットにまとめてから
rebase した(squash merge なので結果は同じ).
- `agents/hooks/lib/static_rule_scan.py`:#202 の「設定ごとの基準ディレクトリから repo
相対パスで走査する」(`scan_root`,`cwd=root`,`--`)と,この PR の `Report`(error と advice
の分離),`note` の表示,信頼判定を両方残した.
- #202 の,git の無いプロジェクトでマニフェストのディレクトリを基準にするフォールバックと,そのテストは削除した.ユーザーの決定
(a) により共有規則は信頼できるリポジトリの中でしか走らないので,このフォールバックには到達しない.
- `tests/test_ast_grep_rules.py`:#190 の「error の規則は note を持つ」テストが,この PR の
`NOTE_PATTERN` を同名で上書きしていた.#190 の規則ごとのテストを残し,この PR の判定(空のブロック note
も検出する)を使うようにした.
    - `checkout_of` フィクスチャを `tests/conftest.py` に移した.
- 最新(#214,#215,#217,#218 の後):#215 で ADR が MADR の front matter
形式になったので,この PR の改訂日を front matter の `amended` に加えた.#214 が ADR-0021
に足した「Which rules ast-grep may block」の節は,この PR の改訂と矛盾しない.
- 2 回目以降(#191〜#195,#198,#199,#212 の後):テキストのコンフリクトは無かった.#194 で YAML
の規則が入ったので,「規則の言語はすべて抑制ガードの対象」というテストに yaml を加えた.YAML の `ast-grep-ignore`
はもともと検査している.

## 概要

ユーザーの決定:static(ast-grep)規則は,linter のエラーと同じくブロックする.advisory
の段階は設けず,規則は「有効(`severity:
error`,ブロックする)」か「削除」のどちらかとする.まれな正当な例外は,理由を書いた抑制コメントで扱う.抑制コメントはエージェントが勝手に追加してはならず,ユーザーが承認する.

- **ADR-0021 の改訂**(`docs/adr/0021_*.md`)
- static rule は編集時にブロックする.「advisory で始めて昇格する」経路は削除した.jev-lint の model
rule は変えていない.
    - 共有規則は所有者のスタイルなので,信頼できるオーナーのリポジトリでだけ動かす(「Whose style」).
    - error の規則は `note` に修正方法を持つ.抑制ガードはすべてのプロバイダで動く.
-
**ブロック**(`agents/hooks/lint_format.py`,`agents/hooks/lib/static_rule_scan.py`)
- ast-grep が `severity: error` の指摘を返したら,PostToolUse の `{"decision":
"block", "reason": ...}` を返す.
- reason には指摘ごとに,規則 ID,場所,規則の `message`(なぜ誤りか),`note`(`Fix:`
として修正方法)を並べる.その後に 1 回だけ次の指示文を続ける:「Fix the code as shown. Do not move or
split the code to avoid the rule; if a real exception is needed, add a
suppression comment, which is reviewed.」
- error,指示文,advice の順に並べ,全体を 1
つのサイズ上限(`NOTIFICATION_LIMIT_BYTES`)に収める.advice は残りに収まる分だけ入れる.
- error 未満の指摘,linter
の診断,走査の失敗はブロックせず,従来どおり通知する.壊れた走査でエージェントを止めないため.出力が切り詰められても,終了コード 1(error
あり)ならブロックする.
- dsh は PostToolUse で `systemMessage` を読むので,ブロック時は同じ文を `systemMessage`
にも入れる(プロバイダのプロファイルがブロックの形式も決める).
- **共有規則は信頼できるオーナーのリポジトリでだけ動かす**(`static_rule_scan.py`)
- 共有規則(`agents/hooks/lint/sgconfig.yml`)は,チェックアウトの origin のオーナーを
`trusted_owners` が信頼している場合にだけ走る(`AGENT_TRUSTED_OWNERS` も同様).
- 判定するのはオーナーだけ.fork かどうかは問わない.fork かどうかは model rule
が何を読めるかに関わることで,誰のスタイルを当てるかには関わらない.問い合わせをしないので,オフラインでも編集のたびに待たされず,オーナー自身のリポジトリで規則が知らせずに止まることもない.
- それ以外のリポジトリ,リポジトリ外,origin が無い,trusted_owners
ファイルが読めない場合は,共有規則を走らせない.プロジェクト自身の `sgconfig.yml` の規則は,従来どおりどこでも走る.
-
**抑制ガード**(`agents/hooks/guard_suppression.py`,`agents/hooks/lib/comment_nodes.py`,`agents/hooks/lib/patch_input.py`)
- `ast-grep-ignore` と Go の `//nolint` を対象に加えた.`ast-grep-ignore` は
`.go`,YAML,Nix でも検査する.
- **コメントかどうかは ast-grep 自身(tree-sitter)に判定させる**.`ast-grep scan --stdin`
で言語ごとのコメントノードを探す.ブロックコメント,複数行文字列,YAML のブロックスカラー,Rust の raw
string,ヒアドキュメント,JS の `<!--` コメントを正しく扱える.
- 以前は言語ごとに手書きの字句解析をしていたが,文字列の形式を見落とす指摘が続いたため置き換えた.対象の拡張子はすべて ast-grep
が解析できる.
- ast-grep
は,走査するテキスト中の抑制をこの走査自体にも当てはめ,マーカーの下のコメントを隠す.そこで,語を同じ長さの別の語に置き換えてから走査する.設定は空の
`sgconfig.yml` を明示的に渡し,プロジェクトや親ディレクトリの設定は読まない.
    - マーカーは件数ではなく,「効く位置にあるか」と「指示と対象の規則」の組で比べる.1 行にある複数のマーカーは,すべて照合する.
- 範囲は,マーカーからコメントの終わりまで(Rust
の属性は閉じ括弧まで,複数行でも)とする.その中で比べるのは,指示と規則の一覧だけ.たとえば `nolint` は linter
の一覧,`noqa` はコード,eslint は `--` の前まで,biome はコロンの前まで,Rust の属性は `reason =
"..."` を除いた部分.理由文の誤字を直すだけなら通る.`ast-grep-ignore`
は,マーカーの後ろの語をすべて規則名として読むので,コメント全体で比べる.
- Rust
の属性の閉じ括弧は,文字列とコメントの中の括弧を数えずに探す.閉じていない属性はファイルの終わりまでを範囲とする.範囲は,同じ種類の次のマーカーの手前で止める(コメントの中のマーカーで,属性の範囲は切らない).
- 判定の時間はファイルの大きさに比例する(行とノードは二分探索,括弧は 1 回の走査).マーカーが 2 万個のファイルでも 1 秒未満.
- そのため,`//nolint:errcheck` を `//nolint` や `//nolint:govet`
に変えるなど,対象の規則を減らす・変える・加える変更は,新しいマーカーと同じく確認する.`noqa` のコード,`type: ignore`
のコード,eslint の規則(複数行のブロックコメントも),`allow` / `expect` の lint,shellcheck
のコードも同じ.
- 規則名を書かない `ast-grep-ignore`
はすべての規則を抑制するので,規則名の変更も確認する.文字列をコメントに変える変更(同じ行でも,前後の行の変更でも)も確認する.
        - マーカーの移動や削除,マーカーの横のコードの編集は通る.
- ast-grep の走査は,1 回の判定の中で 20 秒の期限を共有する(フックの上限は 30
秒).期限は判定の開始時に決まる.期限で打ち切った走査があれば,コメントが不明なので確認する.
-
ファイル全体で比べるときは,コメントの外の語は数えない(文字列は何も抑制しない).文脈の無い断片(完全一致しないハンクなど)では,コメントの中に入るかどうかを判断できないので,すべてのマーカーをどこにあっても数える.
    - 相対パスは,payload の `cwd`(プロバイダがツールを実行するディレクトリ)を基準に読む.
- Rust の `#[allow(...)]` / `#[expect(...)]` は,Rust
の文字列とコメントの中以外なら数える.マクロ本体の中も数える(展開されると効くため).Rust 以外のファイルでは数えない.
    - ast-grep が無いか失敗したときは,コメントかどうかを判定できない.その場合は次の 2 つを確認する.
        - マーカーのある行が新しく現れた場合.行頭のインデントも比べる(YAML のブロックスカラーから外す変更など).
- マーカーを含むテキストで,変更した行に文字列やコメントの区切り(引用符,`/*`,`-->` と `--!>`,`<<`,YAML の
`|` など)がある場合.
- シェルスクリプトで,マーカーと `<<` を含むテキストの行を変えた場合(heredoc
の終端は記号を持たない語なので,行からは見分けられない).
        - それ以外の,抑制とは関係のない編集は通す.
        - 残る抜け道:ast-grep が無い環境で,区切りを含まない行の変更でマーカーがコメントに変わる場合は検出できない.
- Edit / MultiEdit / エディタの `insert` / Write
は,ファイル全体に適用した前後で比べる(replace_all,行の一部の編集,MultiEdit
の後続の手順も含む).エディタ系ツールのフィールド(`old_str`,`new_str`,`file_text`)も読む.置換がファイルに当てはまらないときは,マーカーを含むファイルなら確認する.
    - apply_patch
- すべてのハンクが既存ファイルに完全一致するなら,適用後のファイル全体で比べる.適用器はまず完全一致を探すので,同じ位置に当たる.
            - Add File は新しい内容そのもので比べる.
            - ハンク中の空行は空の文脈行として扱う.
            - ヘッダ行は前後の空白を除いて読む.
        - 次の場合は位置を判定できないので,マーカーを含むファイルなら確認する.
- 完全一致しないハンク,`*** End of File` のチャンク,解釈できない行,完全一致が 2 か所以上ある場合.
- 同じファイルに 2 回届くパッチは確認する.セクションの重複でも,`Move to:` の移動先でも,別の綴りや大文字小文字の違いでも同じ.
- `Move to:` は移動元と移動先の両方で判定する.移動先で初めて効くマーカーがあれば,それ自体を新しい抑制として確認する.
- 該当するのは,移動元では検査しない拡張子のマーカーと,移動先の文法でだけコメント(または Rust の属性)になるマーカー.
- 判定には,パッチを当てた後の内容を使う(再構築できないときは既存の内容).同じパッチでマーカーを消してから移動するなら通る.
            - `.py` から `.go` のような単なる移動は通る.
- ファイル単位の抑制:ast-grep は,1
行目のマーカーの直後に空行があるとファイル全体を抑制する.この状態になる編集や,この状態のマーカーを変える編集は確認する.1
行目のマーカーは,コメントノードの中にあるときだけ数える(1 行目が `MARKER = "ast-grep-ignore"`
のような文字列なら数えない).
    - 拡張子は小文字にして比べる.行の区切りは ast-grep と同じく改行だけとする.
- **プロバイダへの配線**(`agents/hooks.json`)
    - Devin,Hermes,pi,dsh の編集前フックに `content suppression` を加えた.
    - これらのプロバイダは確認を求められないので,新しい抑制はブロックされる.ユーザーが例外を追加する前提で,意図した挙動.
- **規則テスト**(`tests/test_ast_grep_rules.py`):`severity: error` で `note`
の無い規則があると失敗する.

## ユーザーの決定

- 第三者のリポジトリ:案
(a).共有規則は信頼できるオーナーのリポジトリでだけ走らせてブロックし,それ以外では走らせない.リポジトリ自身の規則は従来どおり.
- 抑制ガードを Devin,Hermes,pi,dsh にも配線し,そこでは新しい抑制をブロックする.Go の `//nolint`
も対象にした.
- ブロックメッセージ:指摘ごとの規則 ID,場所,message,note と,回避を禁じる指示文 1 回.note の無い error
規則は規則テストで落とす.
- レビューの指摘は別の Issue に回さず,この PR で直す.
- やらないこと:回避を検出する jev-lint 規則と,回避コストに関する ADR の基準.

## 文章と規則の対応表

| 規則 ID | 元の場所 | 元の規則(原文) | 判定 | 実装 | 例のテスト | 元の文章 |
| -------- | -------- | ---------------- | ---- |
------------------------------------------------------ | ---------- |
-------- |
| (なし) | — | — | — | hook と ADR の変更のみで,文章を規則に置き換えていない | — | — |

## 戻し方

static rule のブロックだけを止める環境変数のスイッチは無い(`AGENT_MODEL_RULES` は model rule
用で,static rule には効かない).戻すにはこの PR を revert する(squash merge の 1
コミット).急ぐ場合は,問題の規則の `severity` を `warning` に下げれば,その規則だけ従来の非ブロックの通知に戻る.ただし
ADR の「有効か削除か」に反するので,一時的な措置に限る.

## 検証

- `REQUIRE_AST_GREP=1 REQUIRE_JEV_LINT=1 uv run pytest
--cov`(b13175e9,CI と同じ設定):5357 passed,1 skipped.以前手元でだけ落ちていた model rule
のテストも,main の #218 の後は通る.
- `ruff check`,`ruff format --check`,`ty
check`,`ls-lint`,ファイル行数(pre-commit):通過.
- 追加・更新したテストは,各項目とも実装前に失敗することを確認した.
-
ブロック(`tests/hooks/test_static_rules.py`,`tests/hooks/test_lint_format.py`)
        - error でブロックし,reason は指摘と指示文 1 回で,全体が上限に収まる.
        - 実際の ast-grep でもブロックする.問題のないファイルと,規則の対象外の言語はブロックしない.
        - 異常終了した走査はブロックしない.切り詰められても,終了コード 1 ならブロックする.
        - Codex と dsh のアダプタ経由でもブロックする.
    - 信頼判定(`tests/hooks/test_static_rules_trust.py`)
        - 共有規則が走るのは,信頼できるオーナーのチェックアウトだけ.
        - fork の問い合わせはしない.
        - 別オーナーでも,プロジェクト自身の規則は走る.
    - コメントの走査(`tests/hooks/test_comment_nodes.py`)
        - 抑制マーカーの直下のコメントも見つける.
        - 作業ディレクトリの `sgconfig.yml` を読まない.
        - 文字列はコメントにしない.JS の `<!--` はコメントとする.エンコードできないテキストは不明として扱う.
-
抑制ガード(`tests/hooks/test_guard_suppression.py`,`tests/hooks/test_guard_suppression_scope.py`)
        - Codex と自動セキュリティレビューが報告したケースは,すべてテストにした.
- 文字列からコメントへの変化:同じ行,ブロックコメント,Python の複数行文字列,YAML のブロックスカラー,Rust の raw
string,ヒアドキュメント,Go の `"//nolint"`,ast-grep が無いときのテンプレート文字列.
        - 同じ行の 2 つ目のマーカー.
-
対象の変更(`tests/hooks/test_guard_suppression_target.py`):`//nolint`,`noqa`,`type:
ignore`,eslint,`allow` / `expect`,shellcheck
で規則を減らす・変える・加える変更は確認し,移動,削除,横のコードの編集は通る.
- 対象の変更では,属性の中のコメントや文字列にあるマーカーや括弧,閉じていない属性も確認する.理由文だけの修正(8 種類のマーカー)は通る.
- 走査の期限(`tests/hooks/test_guard_suppression_budget.py`):ハングする ast-grep
でも,移動を含むパッチの判定が期限内に終わり,確認する.期限切れの結果は次の判定に持ち越さない.マーカーが多いファイルも 5
秒以内に判定する.import
から時間が経っても,判定の外の走査は期限切れにならない(`tests/hooks/test_comment_nodes.py`).
- ast-grep が無いとき(`tests/hooks/test_guard_suppression_unparsed.py`):YAML
のインデント変更と heredoc 終端の挿入は確認し,heredoc の無いスクリプトの無関係な編集は通る.
        - payload の `cwd` にある相対パスのファイルを読む.
        - Rust の属性:raw string からコードへの変化,マクロ本体,Python のコメントから Rust への移動.
- パッチ:` ***`
で始まる文脈行で区切りが終わらない,配置できないハンクの断片で文字列に見えるマーカー,文脈行がコメントに変わる場合,Add
File,空行,`*** End of File`,解釈できない行,複数の一致,同じファイルへの重複(別の綴り,大文字小文字,移動先).
        - 移動:両方で効くマーカーは通る.移動先でだけ効くマーカーは確認する.
        - ast-grep が無いときは,抑制と関係のない編集を通す.`--!>` の変更は確認する.
- 1 行目の文字列はファイル単位の抑制にならない.移動の途中でマーカーを消せば通る.完全一致しないハンクが引用符の中に語を加えると確認する.
- apply_patch のテストは `tests/hooks/test_guard_suppression_patch.py`
に分けた(ファイル行数の上限のため).
- プロバイダ(`tests/test_provider_adapters.py`):5 つのアダプタすべてで,新しい抑制がブロックされる.
- 規則テスト(`tests/test_ast_grep_rules.py`):note の無い error 規則を検出する.main の
error 規則 28 件すべてに適用している.

## レビュー対応

- Codex,claude-review,自動セキュリティレビューの指摘は,すべてこの PR
で修正した.各スレッドにはコミットを添えて返信し,resolve した.
- 以前の返信にあるコミット ID の一部は,rebase の前のもの.
- 修正したもの
    - dsh のブロック表示.
    - 文字列からコメントへの変化.ここから,手書きの字句解析を tree-sitter に置き換えた.
    - 複数行コメント,YAML のブロックスカラー,Rust の raw string.
    - `//nolint` などのコメントの指示の判定.
    - 同じ行の 2 つ目のマーカー.
    - パッチの文脈行と配置.
    - ast-grep が無いときの判定.安全側に倒しつつ,抑制と関係のない編集は止めない.
    - ブロック全体の大きさ.
    - 拡張子をまたぐ移動.
    - 信頼判定の問い合わせ待ちと,規則が知らせずに止まる問題.
    - Rust の属性.
- CodeQL の HTML
コメントの終わり(`--!>`),ファイル単位の抑制のコメント判定,移動先で効くマーカーの判定に使う内容,断片の数え方.
    - 抑制の対象の変更(`//nolint:errcheck` → `//nolint` など)と,理由文の修正での誤検知.
    - 走査のタイムアウトの積み重ね,マーカーの多いファイルでの二乗の処理時間,属性の範囲の切り方と括弧の対応.
- ` ***` で始まる文脈行,payload の `cwd`,配置できないハンクの断片,ast-grep が無いときのインデントと
heredoc.
- CI の test ジョブの失敗:走査の期限が import の時点で決まっていたため,遅い実行では判定の外の走査が期限切れになっていた.
- 変えていないもの
    - 走査が失敗したときにブロックしない点:ADR の方針(壊れた走査でエージェントを止めない)どおり.
- この PR で入れた変更について jev-lint が出した advisory
の指摘(`command-query-naming`,`error-message-names-operation`)
- `_adds`,`_insert_change`,`_scan_within_budget` は query の名前に改め,走査の副作用は
`_scan` に寄せた.
    - `_patch_changes` は,返す値で命名した query なので当てはまらない.
    - `lint_format.py` の `TypeError` の文言は,この PR より前からある.
    - 規則そのものの扱いは #196 で記録する.

## 制限

完全な構文解析が要る理論上の抜け道で,この PR では扱わないもの.

- ast-grep
が無いか失敗したときは,行単位の推測で判定する.区切りの記号を含まない行の変更でマーカーがコメントに変わる場合(シェル以外の言語)は検出できない.ast-grep
は CI と dev shell で必須.期限切れは常に確認する.
-
指示と規則の一覧は,ツールごとの書式を正規表現で近似して切り出す.ツールが受け付けるのに正規表現が拾わない書き方で規則を足すと,理由文として扱われて見落とす.ツールの構文解析器を使えば防げるが,ツールごとの依存が増える.
- Rust の属性の範囲は,ast-grep
の文字列とコメントのノードを除いて括弧を対応づける.マクロの中の不均衡な括弧のように,tree-sitter と rustc
の解釈がずれる箇所は追わない.
- heredoc の判定は `.sh` と `.bash` に限る.他の言語の heredoc(Ruby,Perl
など)は対象の拡張子に無い.

## フォローアップ

- なし.

## ユーザーの判断事項

- 信頼できないリポジトリでも,そのリポジトリの `sgconfig.yml` にある `severity: error`
規則はブロックする.その規則の `message` と `note` は,エージェントへの指示としてそのまま渡る.
    - ユーザーの決定(プロジェクト自身の規則は従来どおり)に沿って変えていない.ただし,ブロックはこの PR で新しく入る挙動.
    - この PR の前も,同じ文言は通知として渡っていた.
    - ブロックするかどうかと,文言の扱いを信頼判定に合わせるかどうかは,ユーザーの判断事項.

## マージ後すぐ直す指摘

この PR では直さず,マージ直後のフォローアップ PR で直す(#216 と同じ扱い).

- markdown セルを code セルに変える NotebookEdit
で,比較元に旧本文が入る.元の本文にあるマーカーが変わらないものとして扱われ,確認なしで通る.
- Rust の属性で,`reason = "..."` の項目自体の追加・削除まで比較から外れる.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: furedea <132188853+furedea@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
furedea pushed a commit that referenced this pull request Nov 18, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.2.0](v0.1.4...v0.2.0)
(2026-11-18)


### Features

* add adr-check command for MADR ADRs
([#225](#225))
([138c542](138c542))
* **adr:** adopt the shared ADR checks
([#226](#226))
([5c94a78](5c94a78))
* **hooks:** block edits on static rule errors and guard ast-grep-ignore
([#203](#203))
([f5b3317](f5b3317))
* **hooks:** judge gh calls by effect through a policy table
([#201](#201))
([db7226d](db7226d))
* **hooks:** keep ask prefixes only for widening authority and promotion
([#199](#199))
([c3985f6](c3985f6))
* **hooks:** migrate TypeScript style rules to ast-grep and jev-lint
checks ([#195](#195))
([24d1a3e](24d1a3e))
* **lint:** flag Go packages under util and common with an error rule
([#202](#202))
([de25e1d](de25e1d))
* **lint:** judge ADR rationale with Jev
([#228](#228))
([cf1c0a3](cf1c0a3))
* **lint:** migrate agents/AGENTS.md rules to model rules and linters
([#191](#191))
([9e3e37d](9e3e37d))
* **lint:** migrate bash-style and github-actions-style rules to checks
([#194](#194))
([4e473ba](4e473ba))
* **lint:** migrate go-style rules to ast-grep and jev-lint rules
([#190](#190))
([296ad84](296ad84))
* **lint:** migrate rust-style prose rules to checks
([#193](#193))
([e184682](e184682))


### Bug Fixes

* **ci:** run the jev-lint model-rule tests in CI
([#218](#218))
([1919b06](1919b06))
* **deps:** pin dependencies
([#221](#221))
([5d083e4](5d083e4))
* **hooks:** deny git options that skip repository hooks
([#212](#212))
([e10e5b6](e10e5b6))
* **hooks:** judge a cell turned into code from scratch and ignore
attribute reasons
([#224](#224))
([96fb561](96fb561))
* **lint:** close blocking ast-grep rule gaps recorded in
[#196](#196)
([#216](#216))
([fa31947](fa31947))
* **skills:** drop the agent-run verify step that protected records
block ([#213](#213))
([700244d](700244d))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: furedea-release[bot] <353651101+furedea-release[bot]@users.noreply.github.com>
furedea added a commit that referenced this pull request Nov 20, 2026
…es and the Stop resume (#260)

## 概要

#196 の misc グループ(bash / GitHub Actions,hook,共有の項目)を片付ける.bash・yaml のモデル規則
6 件で,見逃していた書き方を選ぶようにし,eval を取り直して cutoff を当て直した.Stop の resume が別の review
構成で再開してしまう不具合も直した.判断が必要な項目はない.

Refs #196

## 変更前と変更後

| 対象 | 変更前 | 変更後 |
| --- | --- | --- |
| `workflow-default-shell` / `cache-key-and-trust` | flow 形式の step(`-
{run: …}`,`steps: [{uses: …}]`)を選ばない | 選ぶ |
| `job-permissions-least-privilege` | 引用符付きの `"jobs":`,flow 形式の job の
`permissions` を選ばない | 選ぶ |
| `usage-help-and-error-exits` | `$#` を調べる `if`,getopts の bare な `h)`
を選ばない | 選ぶ |
| `function-variables-local-near-use` | `: "$((count++))"` を選ばない | 代入を含む
`$(( ))` を選ぶ(`$((1 + 2))` は選ばない) |
| `tracing-not-left-on-for-secrets` | `set -xe`,`set -euxo pipefail`
を選ばない(#243 の Limit) | 選ぶ.bad fixture を 1 件追加 |
| Stop の resume | 失敗後にコミット構成が変わっても(`git reset --soft`),保存した位置から再開し,未実行の
review を飛ばす | resume に review 構成(base・rules・files)の digest
を保存し,一致しなければ最初からやり直す |

## 検証

- [x] `tests/test_bash_and_yaml_model_rules.py`(新規,dry-run の選択テスト 15
件):変更前は 11 件失敗,変更後はすべて成功
- [x] `tests/hooks/test_model_rules_resume.py`:別構成の resume
で最初からやり直すテストを追加(変更前は失敗)
- [x] `jev-lint eval --accept`(ユーザーが実行,2026-11-19,3 passes):6 suite の
baseline を記録
- [x] `jev-lint eval --replay agents/hooks/lint/model-rules`:74 suite
がすべて as shipped
- [x] `uv run pytest`(jev-lint 0.7.0 を `PATH` に置く):6188 passed,2 skipped
- [x] `ruff check`,`ruff format --check`,`ty check`(pre-commit)

## eval の結果(3 passes,中央値)

| 規則 | tp / fp / fn | 最高の clean | 最低の bad | cutoff |
| --- | --- | --- | --- | --- |
| `bash/usage-help-and-error-exits` | 4 / 0 / 0 | 0.45 | 0.83 |
0.64(据え置き) |
| `bash/function-variables-local-near-use` | 4 / 0 / 0 | 0.17 | 0.79 |
0.49(据え置き,blind) |
| `bash/tracing-not-left-on-for-secrets` | 4 / 0 / 1 | 0.16 | 0.16 |
0.5(分離しない) |
| `yaml/cache-key-and-trust` | 4 / 0 / 0 | 0.20 | 0.94 |
0.57(据え置き,blind) |
| `yaml/job-permissions-least-privilege` | 3 / 0 / 0 | 0.40 | 0.91 |
0.64 → 0.65(blind) |
| `yaml/workflow-default-shell` | 4 / 0 / 0 | 0.41 | 0.86 | 0.62 →
0.63(`inconclusive:` を削除) |

- `job-permissions-least-privilege` の `inconclusive:` は,指示では削除だった.しかし
margin が 0.26 / 0.25 で jev-lint の blind 判定(0.25 以上)に当たり,削除すると replay
が失敗する.このため残し,数値だけ 0.28 から 0.25 に直した.
- `cost`:eval 1 回(6 suite,ユーザー実行).このセッションでは model に問い合わせていない.

## #196 の misc 項目

| 項目 | 状態 |
| --- | --- |
| `gha_workflow_permissions_deny_all`:引用符付きの `"jobs":`,ルート全体が flow
mapping | 対応済み(#216.引用符は修正,flow は `Scope:` に記録) |
| `bash_readonly_constant_name`:関数内の `readonly`,`declare -r` |
対応済み(#216.`declare -r` / `-gr` は検査,関数内の `readonly` は `Scope:` に記録) |
| `gha_job_timeout_minutes`:`jobs` が flow mapping,引用符付きの `"jobs":` |
対応済み(#216.引用符は修正,flow は `Scope:` に記録) |
| `gha_pinned_uses_version_comment`:`action.yml` | 対応済み(#216.`files:` に
`action.yml` を追加) |
| `gha_workflow_concurrency` の
`'on':`,`gha_workflow_default_shell`,`bash_strict_mode_header` | 不要(#194
でモデル規則に降格) |
| `.bats` を ast-grep で Bash として読むか | 対応済み(#216.有効化しないと決定) |
| `SUBJECT_CAP` | 対応済み(#246) |
| `scripts/bootstrap_server.sh` に ast-grep がない(#202) | 対応済み(#216) |
| 後段 review の失敗で毎ターン block する件,失敗理由,`skipped_files`,2 tier の順序のテスト(#191)
| 対応済み(#216) |
| resume が別の review 構成に当たる(#216 のレビュー) | **修正**(この PR) |
| `workflow-default-shell` の flow step | **修正** |
| `job-permissions-least-privilege` の引用符付き `"jobs":`,flow job |
**修正**(`jobs` そのものが flow mapping の場合は対象外.下の Limits) |
| `cache-key-and-trust` の flow step | **修正** |
| `usage-help-and-error-exits` の `$#`,bare な `h` | **修正** |
| `function-variables-local-near-use` の `: "$((count++))"` | **修正** |
| `tracing-not-left-on-for-secrets` のフラグ連結(#243 の Limit) | **修正** |
| `SKILL_NAMES` が `.` で始まるディレクトリを拾う | 対応済み(#214) |
| `test_main_is_thin_selects_…` を `command-query-naming` が指摘する |
対応しない.advisory な余分の指摘で,テスト名が `selects` なのは matcher の選択を検証するため |
| `error-message-names-operation` が
`guard_git.py:46`,`herdr_ownership.py:26` を指摘する(#216) | 対象外.guard 系 hook
は #197 / #255 の担当 |
|
`no-comment-restating-code`,`no-exposed-mutable-collection`,`no-reaching-through-collaborators`,`construction-separate-from-execution`(言語ごと)
| 各言語レーンの担当.規則ファイルが言語ごとに分かれていて,共有ファイルがない |

<details><summary>Limits と範囲</summary>

- Limit:`tracing-not-left-on-for-secrets` は,`set +x` のあと秘密の前で再び `set -x`
するケース(`bad_retraced_before_secret.bash:10`)を 0.16 と判定し,clean
と分離しない.advisory のまま rule.yml に記録した.
- Limit:`job-permissions-least-privilege` と `workflow-default-shell`
は,`jobs` 自体が flow mapping(`jobs: {build: {...}}`)の workflow
を選ばない.実際にはほぼ書かれない形.
- Limit:`usage-help-and-error-exits` の bare な `h)` は,getopts ではない `case`
の `h)` も選ぶ.モデル規則の matcher は広く取る方針(#196)なので,criteria で判定する.
- Limit(レビュー指摘,P2):`cache-key-and-trust` は,別のアクションの入力(`with: {uses:
actions/cache@v4}`)も選ぶ.余分な subject で,block 形式にも以前からある.祖先の条件で step の
mapping に限る修正は matcher を変えて eval の取り直しが要るため,次の eval で直す.
- Limit(レビュー指摘,P3):`function-variables-local-near-use` は,`$(( flags <<=
1 ))` のように `<<=` / `>>=` で代入する `$(( ))` を選ばない.次の eval で `(<<|>>)=` を加える.
- Limit(#243 から継続):`script-constants-readonly`
は,同じ変数をトップレベルで再代入するスクリプトで余分に指摘し得る.
- 古い receipt(`layout` なし)の resume は,一致しないものとして扱い,最初からやり直す.
- 範囲外:Jev 規則の昇格(ADR-0027),guard / permission hook,#181,release.

</details>

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: furedea <132188853+furedea@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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