Skip to content

feat(hooks): migrate TypeScript style rules to ast-grep and jev-lint checks - #195

Merged
furedea merged 28 commits into
mainfrom
feat/migrate-typescript-style-rules
Nov 15, 2026
Merged

furedea merged 28 commits into
mainfrom
feat/migrate-typescript-style-rules

Conversation

@furedea-agent

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

Copy link
Copy Markdown
Contributor

Refs #74(TypeScript 担当)
Refs #196

計画:#74 (comment)

概要

agents/skills/typescript-style/ の規則を 1 文ずつ洗い出し,判定できる最も安い道具へ移した(ADR-0021).

  • ast-grep(最終): この PR が残す TypeScript の ast-grep 規則は 0 件.不安定な 3 規則(ts_no_unvalidated_json_cast,ts_catch_rethrow_requires_cause,ts_no_other_test_framework)は review が収束しないため削除し,oxlint へ移す(下の「ast-grep から外した規則と理由」).
  • ast-grep(削除): ts_readonly_property,ts_readonly_array_property,ts_no_home_dir_in_tests(文章は残す),ts_no_namespace_import(規則も文章も削除).
  • jev-lint: 8 規則を model-rules/typescript/<id>/rule.yml に追加(threshold: 0.5,severity: warning).prose は残す(ADR-0021).fixture・eval・baseline は未追加.
  • 既存 linter が覆う文章は,template-typescript の main で有効な規則を確かめ,同じ PR で削除した.完全には覆われない部分は残した.
  • 共有ファイルの変更: tests/test_model_rule_files.py の TypeScript 用の選択数テストだけ(jev 規則の追加に伴う期待値の更新).

最終の ast-grep 規則

なし(TypeScript の blocking な ast-grep 規則は残さない).

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

blocking にする規則は安定していなければならない.次の規則は review のたびに新しい指摘が出て収束しなかった(11〜26 件)ため,既存の linter に任せることにした.判断の基準は ADR-0021 に記録する.

規則 行き先 review の指摘数 不安定の型 例
ts_no_unvalidated_json_cast / tsx_ oxlint typescript/no-unsafe-type-assertion,no-unsafe-assignment,no-unsafe-return(https://github.com/furedea/template-typescript/pull/44) 26 1(変数の宣言型や import 先を見られない),4(as / <T> / ! / satisfies / 注釈 / 戻り値型の書き方が多い) 誤検出:const x: unknown | null = JSON.parse(t).見逃し:JSON.parse(t) as Record<string, unknown>
ts_catch_rethrow_requires_cause / tsx_ oxlint preserve-caught-error(https://github.com/furedea/template-typescript/pull/44) 11 2(捕捉した値が使われるかを追う),4(new なし,cause の渡し方,.catch など) 誤検出:new AppError({ message, cause: error }).見逃し:new Error(message)
ts_no_other_test_framework / tsx_ oxlint no-restricted-globals(スコープを見る)と no-restricted-imports(template-typescript の新しい PR.番号は作成後に追記) 12 2(jest が局所変数・引数・分割代入・catch の引数などに隠されるかをスコープで追う) 誤検出:const { jest } = makeFormatters(); jest.format(),catch (jest) { jest.format() }

文章(typescript-style)は,template の PR がマージされるまで残す.

文章と規則の対応表(全規則)

場所は agents/skills/typescript-style/ からの相対パス,実装は agents/hooks/lint/ からの相対パス.

規則 ID 元の場所 元の規則(原文) 判定 実装 例のテスト 元の文章
(削除)ts_no_namespace_import references/code_style.md(#117 で削除済み) 名前空間 import を避ける 規則を削除 — — 文章は #117 で削除済み.ユーザーの判断で規則(ts_ / tsx_)も削除した(Zod 4 が import * as z from "zod" を勧めるなど,名前空間 import は問題ない)
(ls-lint) references/code_style.md Use snake_case file names (enforced by ls-lint) 既存 linter(template-typescript の .ls-lint.yml の .*: regex) — — 削除(新規プロジェクトは template から作る,というユーザーの方針)
(wave 2) references/code_style.md Name files by the domain or action, not a role suffix 既存 linter(ls-lint,有効化が必要) — — 残す(波 2 に記載)
ts_no_vague_name references/code_style.md Avoid manager, helper, util, and common unless the name is already established locally 文章のまま — — 残す.Manager / Helper / Util / Common を含む識別子は常に誤りとは限らず,静的規則だと編集を止めてしまうため,ユーザーの判断で規則を削除した(ts_no_vague_name / tsx_no_vague_name)
(oxlint) references/code_style.md Use import type for type-only imports 既存 linter(template-typescript の typescript/consistent-type-imports(tsc verbatimModuleSyntax)) — — 削除
(oxlint) references/code_style.md Do not create import cycles 既存 linter(template-typescript の import/no-cycle) — — 削除
(oxfmt) references/code_style.md Let oxfmt define formatting. Do not hand-format around it 既存 linter(template-typescript の pnpm run format:check(oxfmt)) — — 削除
— references/code_style.md Keep user-facing wording separate from logic, in a dedicated module such as src/copy/ 文章のまま — — 残す.文言かどうかとモジュール配置の判断はプロジェクト構成に依存し,構文からも関数単位でも yes/no にできない
comment-explains-why references/code_style.md Comments explain why, not what jev-lint model-rules/typescript/comment-explains-why/rule.yml なし(保留) 残す(ADR-0021)
comment-explains-why references/code_style.md Prefer clear types, function names, and module boundaries over explanatory comments jev-lint(同上) 同上 なし 残す(ADR-0021)
— references/code_style.md Architectural choices, dependency decisions, and external-tool boundary rules belong in ADRs 文章のまま — — 残す.記録先の方針で,コードに現れない
expected-failure-returned-as-value references/errors.md Return expected failures as values (Result) jev-lint model-rules/typescript/expected-failure-returned-as-value/rule.yml なし 残す
— references/errors.md Define the Result type once and reuse it 文章のまま — — 残す.複数ファイルにまたがる重複で,1 関数・1 ファイルの判定にならない
— references/errors.md Make error a union of tagged variants when callers branch on the failure category 文章のまま — — 残す.呼び出し側の分岐は他ファイルにあり,その場で見えない
expected-failure-returned-as-value references/errors.md throw only for programmer errors and unrecoverable states jev-lint(上と同じ規則) 同上 なし 残す
ts_catch_rethrow_requires_cause references/errors.md Add context when rethrowing or converting: new Error(message, { cause }) oxlint preserve-caught-error(ast-grep 規則は削除) — — 残す(値への変換と「操作と対象を名指す」は規則が覆わない.後者は既存の error-message-names-operation)
error-message-names-operation(既存) references/errors.md The message names the operation and subject jev-lint(既存規則) model-rules/typescript/error-message-names-operation 既存 残す
(波 2) references/errors.md Do not swallow errors with an empty catch 既存 linter(template-typescript の no-empty(allowEmptyCatch: false)) — — 一部削除(空ブロックは linter が覆う.コメントやログだけの catch も握りつぶしである,という点を残した)
(oxlint) references/errors.md Await or explicitly handle every promise; do not disable no-floating-promises / no-misused-promises / await-thenable 既存 linter(template-typescript の typescript/no-floating-promises / no-misused-promises / await-thenable) — — 削除
states-modeled-as-discriminated-union references/types.md Model states and kinds as discriminated unions with a tag field, not optional fields or flags jev-lint model-rules/typescript/states-modeled-as-discriminated-union/rule.yml なし 残す
(波 2) references/types.md Handle a union with an exhaustive switch whose default assigns satisfies never 既存 linter(template-typescript の typescript/switch-exhaustiveness-check) — — 一部削除(網羅性は linter が覆う.default で satisfies never を代入する形だけ残した)
— references/types.md Represent values with validation or invariants as branded types created by a validating parse function 文章のまま — — 残す.値オブジェクト一般は agents 担当の AGENTS.md の規則.ブランドの作り方は 1 関数では判定できず,jev 規則にすると同規則と重複する
ts_readonly_property references/types.md Declare properties readonly … by default 文章のまま — — 残す.ユーザーの判断で ast-grep 規則は削除した(「既定」の例外が稀でなく,構文から可変の意図を区別できない).typescript/prefer-readonly は template-typescript で別途有効化する予定(この PR では未実施)
ts_readonly_array_property references/types.md … and arrays readonly T[] by default 文章のまま — — 残す.ユーザーの判断で ast-grep 規則は削除した(「既定」の例外が稀でなく,構文から可変の意図を区別できない).typescript/prefer-readonly は template-typescript で別途有効化する予定(この PR では未実施)
ts_readonly_array_property references/types.md Do not expose a mutable raw collection from a domain type 文章のまま — — 残す.ユーザーの判断で ast-grep 規則は削除した(「既定」の例外が稀でなく,構文から可変の意図を区別できない).typescript/prefer-readonly は template-typescript で別途有効化する予定(この PR では未実施)
ts_no_unvalidated_json_cast references/types.md Accept external input as unknown and parse it once at the boundary oxlint typescript/no-unsafe-type-assertion / no-unsafe-assignment / no-unsafe-return(ast-grep 規則は削除) — — 残す(環境変数・storage など他の境界,「一度だけ検証」は覆わない)
type-assertion-follows-validation references/types.md Do not use as casts except immediately after validation jev-lint model-rules/typescript/type-assertion-follows-validation/rule.yml なし 残す
(oxlint) references/types.md Do not use any; use unknown and narrow 既存 linter(template-typescript の typescript/no-explicit-any) — — 削除
— references/types.md Group arguments into a type only when it names a real domain concept 文章のまま — — 残す.agents 担当の AGENTS.md に同じ規則があり,ここで別に判定しない
ts_no_other_test_framework references/testing.md Use only vitest as test framework; do not add Jest oxlint no-restricted-globals / no-restricted-imports(ast-grep 規則は削除) — — 残す(package.json への依存追加と「globals を有効にする」設定は覆わない)
— references/testing.md Run tests with pnpm run test 文章のまま — — 残す.実行手順
repeated-cases-use-it-each references/testing.md Use it.each for the same behavior across multiple inputs jev-lint model-rules/typescript/repeated-cases-use-it-each/rule.yml なし 残す
mock-only-external-boundaries references/testing.md Prefer fake implementations over mocks. Use vi.mock only for external dependencies at module boundaries jev-lint model-rules/typescript/mock-only-external-boundaries/rule.yml なし 残す
inject-time-and-randomness references/testing.md Inject time and randomness as arguments instead of reading Date.now() / Math.random() inside logic jev-lint(エントリポイントでの読み取りは正当なので ast-grep にしない) model-rules/typescript/inject-time-and-randomness/rule.yml なし 残す
ts_no_home_dir_in_tests references/testing.md Do not touch the real home directory 文章のまま — — 残す.ユーザーの判断で ast-grep 規則は削除した(HOME の退避と復元のための読み取りと区別できない)
known-defect-marker-names-removal(既存) references/testing.md Record a reproduced defect with test.fails and a comment naming the removal condition; remove the marker in the fixing change jev-lint(既存規則) model-rules/typescript/known-defect-marker-names-removal 既存 残す(マーカーを外す手順は規則が覆わない)
— references/testing.md Mutation Testing: use StrykerJS 10.x with the Vitest runner; add dev dependencies only when needed 文章のまま — — 残す.道具の選択と導入時期の方針
— references/testing.md Set "testRunner": "vitest" in stryker.config.json 文章のまま — — 残す.設定を作る手順.JSON 設定は編集後 hook の走査対象外で,Stryker を使うときだけ関係する
— references/testing.md Scope a run to the changed module (pnpm exec stryker run --mutate ...) 文章のまま — — 残す.実行手順
— references/testing.md Read survivors in the clear-text output or the HTML report 文章のまま — — 残す.作業手順
— references/testing.md Keep .stryker-tmp/ and reports/ out of version control 文章のまま — — 残す..gitignore の内容で,編集後 hook の対象外
— references/testing.md Unit test: *.test.ts next to the module 文章のまま — — 残す.配置は vitest の include 設定で決まり,構文から判定できない
— references/testing.md End-to-end test: under tests/ 文章のまま — — 残す.同上
— references/testing.md Helper function: prefer local helpers when setup is lightweight 文章のまま — — 残す.好みの方針
mock-only-external-boundaries references/testing.md Fake implementation: prefer explicit fake objects over global mocks jev-lint(上と同じ規則) 同上 なし 残す
— references/tooling.md Use pnpm only; do not mix in npm or yarn, no competing lock file 文章のまま — — 残す.package.json と lock ファイルの運用で,ソースの構文に現れない
— references/tooling.md Install from the lock with pnpm install --frozen-lockfile 文章のまま — — 残す.実行手順
— references/tooling.md Add dependencies with pnpm add / pnpm add -D 文章のまま — — 残す.実行手順
— references/tooling.md Do not use @latest-style version shortcuts 文章のまま — — 残す.文書やコマンド履歴が対象で,ソースの構文に現れない
— references/tooling.md Do not edit pnpm-lock.yaml manually 文章のまま — — 残す.編集経路の方針
— references/tooling.md Do not add a dependency only because it is common 文章のまま — — 残す.追加の動機の判断
— references/tooling.md Formatting is oxfmt, linting is oxlint, type checking is oxlint --type-aware --type-check 文章のまま — — 残す.道具の選択の記述
— references/tooling.md Do not add ESLint, Prettier, or another type checker 文章のまま — — 残す.道具の選択.package.json の依存は構文走査の対象外
— references/tooling.md Keep the strict tsconfig.json options and never loosen them 文章のまま — — 残す.JSON 設定は編集後 hook の走査対象外(ast-grep の JSON 規則を置いても走らない)
(knip) references/tooling.md Detect unused files, exports, and dependencies with knip 既存 linter(template-typescript の pnpm run knip(check にも含まれる)) — — 削除
— references/tooling.md Store production code in src/ 文章のまま — — 残す.配置の方針
— references/tooling.md Colocate unit tests as *.test.ts; e2e tests in tests/ 文章のまま — — 残す(testing.md と同じ理由)
— references/tooling.md Enforce layer boundaries with no-restricted-imports 文章のまま — — 残す.層の定義はプロジェクトごとの .oxlintrc.json で,共有の規則にできない
(波 2) references/tooling.md Avoid utils.ts and helpers.ts; name modules by domain or action 既存 linter(ls-lint,有効化が必要) — — 残す(波 2 に記載)
— references/tooling.md Confirm verification results; run through package.json scripts, not the underlying binaries 文章のまま — — 残す.実行手順(tsdd の検証方針)
— SKILL.md Scope: routine edits do not authorize introducing Nix or changing GitHub settings 文章のまま — — 残す.作業範囲の方針
— SKILL.md Read only the references relevant to the current task 文章のまま — — 残す.案内.表の「code_style」行から imports と formatting を除いた

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

テンプレートは変更していない.no-empty と typescript/switch-exhaustiveness-check は template-typescript で有効になったため表から外した.残る規則を有効化すれば,右端の文章を削除できる.

repo 設定ファイル 規則 ID 置き換える文章
furedea/template-typescript .ls-lint.yml .ts / .tsx の名前に utils / helpers / util / helper / manager / common と役割接尾辞(formatter など)を禁じる regex code_style.md「Name files by the domain or action…」,tooling.md「Avoid utils.ts and helpers.ts」,code_style.md の「Avoid manager…」のうちファイル名の部分
  • 再レビュー対応(この PR の最終): 受け手の名前に依存しない json() の型アサーション,.catch のコールバック(引数を束縛する場合),再エクスポートと動的 import,追加のフレームワーク名,ジェネレーターの境界を直した.以前の対応:ts_no_unvalidated_json_cast は json() の受け手を res / response 系の名前に限り,型付き引数の既定値も対象にした.ts_catch_rethrow_requires_cause は .catch のコールバックも見る.ts_no_other_test_framework は動的 import() / require() も見る.repeated-cases-use-it-each は describe.each の表の呼び出しを除く.

  • ブロックする 3 規則(ts_ / tsx_)の message に失敗の理由,note に直し方(before / after の 1 行)を書いた(PR feat(hooks): block edits on static rule errors and guard ast-grep-ignore #203 の blocking hook が両方を表示する).

検証

  • ast-grep test --config agents/hooks/lint/sgconfig.yml --skip-snapshot-tests: 15 件通過
  • REQUIRE_AST_GREP=1 nix develop --command uv run pytest: 4864 passed,1 skipped

後続(再レビューの上限で保留した指摘)

  • repeated-cases-use-it-each: Vitest の suite(...) も describe と同じく選ぶ.
  • inject-time-and-randomness: Date()(new なし)と括弧なしの new Date も選ぶ.
  • comment-explains-why: アロー関数・関数式の親が jsx_expression,export_statement,assignment_expression,配列などの場合も subject にする.
  • inject-time-and-randomness: crypto.getRandomValues(...) も乱数の読み取りとして選ぶ.
  • expected-failure-returned-as-value,comment-explains-why,inject-time-and-randomness: オブジェクトプロパティ(pair)に束縛した関数も subject にする.
  • type-assertion-follows-validation と angle-bracket-assertion-follows-validation: state を located にする.
  • comment-explains-why: 関数外コメントの subject に隣接コードを渡すため state を located にする.
  • expected-failure-returned-as-value: export default () => { throw ... } のように export_statement に直接置かれた関数も subject にする.
  • mock-only-external-boundaries: vi.spyOn(client, "send") のように定義元が呼び出しから分からない場合のため,state を located にして周辺コードを渡す.
  • inject-time-and-randomness: bare な randomInt(...) などは import 元を確認せず over-match する(同名ヘルパーにも一致).state を located にするか criteria の false 側に加える.

🤖 Generated with Claude Code

…checks

Add seven ast-grep rules (each with a tsx counterpart) and seven jev-lint
model rules for typescript-style, and delete the prose that an enabled
linter rule or a new ast-grep rule fully replaces.

Refs #74

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-15T14:10:44.629850Z 3e46aed 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 (read-only)

Blocking findings: 0 (P0: 0, P1: 0)

  • P2: ts_readonly_array_property and tsx_readonly_array_property also report arrays in inline object types inside parameters and function types. This contradicts the rule's own note and the sibling ts_readonly_property rule. Details are in the inline comment.

What I checked, with no further findings:

  • The ts_ and tsx_ rule pairs match except for id, language, note, and the files globs.
  • ts_catch_rethrow_requires_cause: a function declared inside the catch stops the search, as intended.
  • ts_no_unvalidated_json_cast, ts_no_vague_name, ts_no_other_test_framework: the logic matches their notes.
  • The 7 jev-lint rules and the updated expected counts in tests/test_model_rule_files.py.
  • The prose deletions, against the template-typescript linter config cited in the PR body.

Not verified:

  • I couldn't run ast-grep test or pytest in this environment, so the rule tests and the updated counts are unconfirmed.
  • No test covers the files globs on ts_no_home_dir_in_tests, because ast-grep test ignores them. The hook passes absolute project paths to the shared config, so it is worth checking by hand that the rule actually fires on *.test.ts files.

🤖 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: 8b41c4c477

ℹ️ 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".

…et and var JSON annotations

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

レビューまとめ

ブロックする指摘(P0/P1)はない.

  • P2: ts_readonly_property / ts_readonly_array_property(tsx_ 版も同じ)の union_type / intersection_type の分岐が,宣言以外のオブジェクト型も報告する.対象は引数,戻り値,変数注釈,型引数(例: (o: { a: string } | null),{ label }: { label: string } & BaseProps,useState<{ n: number } | null>).規則の note では「parameters are left alone」と書いているのに,それと逆の動きになる.rule-tests にもこの形の valid ケースがない.

その他の ast-grep 規則(catch 内の cause,home dir,test framework,JSON キャスト,曖昧な名前),jev-lint の model rule 7 件,tests/test_model_rule_files.py の期待値更新は目で確認した.大きな問題は見当たらなかった.なお,ast-grep をこの環境で実行できなかったので,rule-tests は実行していない.

@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: 069d274741

ℹ️ 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".

…ket JSON casts

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

I found no P0 or P1 problems. I reviewed the 7 ast-grep rules (and their tsx versions), the 7 jev-lint model rules, the deleted prose, and the updated selection counts in tests/test_model_rule_files.py.

Findings (both P3, inline):

  • ts_readonly_array_property / tsx_: tree-sitter nests union_type to the left, so an array is reported in a union of three or more types only when it is the last member. For example, string[] | null | undefined is missed.
  • ts_no_vague_name / tsx_: the suffix regex also catches function names such as findCommon, isCommon and getHelper.

Not verified: I reviewed this statically. The environment did not let me run ast-grep test, pytest, or gh pr checks. ts_no_home_dir_in_tests is the first shared rule to use files:. The hook passes absolute paths to the shared config at agents/hooks/lint/sgconfig.yml, and no test runs that glob through the real scan path. It would be worth checking once by hand that **/*.test.ts matches a project file outside the config directory.

🤖 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: e7c8710764

ℹ️ 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".

…rtions in TS rules

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 (0 × P0/P1).

  • P2: references/errors.md: deleting the promise-handling line also drops "do not disable these rules". The linter can't enforce that part (disable comments and config changes get around it), and the rules are only on in projects created from template-typescript.
  • P3: ts_no_vague_name / tsx_no_vague_name miss abstract_class_declaration, so abstract class FooManager isn't reported.

I read the other 6 ast-grep rules (and their tsx_ copies) against the patterns in their rule-tests and found nothing that needs fixing. Readonly arrays, as unknown, nested object types and function-type parameters are excluded as the PR describes. I couldn't run ast-grep in this environment, so I checked all of this by reading the rules, not by running them.

The new jev-lint rules ship with no fixtures or baselines, and threshold: 0.5 hasn't been tuned. The PR says the user chose to defer that, so I didn't count it as a finding. The only test of their selectors is the count assertion in test_typescript_rules_select_the_functions_they_ask_about.

🤖 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: 51af341e6c

ℹ️ 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".

Refs #196

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

I read all 14 ast-grep rules and their rule-tests, the 7 jev model rules, and the change to tests/test_model_rule_files.py. I could not run ast-grep test in this environment, so the result below comes from reading the rules against the tree-sitter grammar.

  • P2 ts_no_unvalidated_json_cast / tsx_no_unvalidated_json_cast: await response.json() as Body without parentheses is not detected, because the patterns require a literal (await ...). Details are in the inline comment.

I found no other correctness or security problems. The stopBy scoping in the catch-rethrow and readonly rules looks correct, the .tsx variants correctly drop the <T> assertion patterns, and the updated count test covers the new model rules.

No blocking findings.

@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: 2295c96e69

ℹ️ 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".

@github-actions

Copy link
Copy Markdown

Review summary

I reviewed this read-only and found no blocking findings (0 × P0/P1). I'm not posting any inline comments.

What I checked:

  • The 8 new jev-lint rules: I read through the selectors by hand.
    • The stopBy boundaries on nested functions look right.
    • The inside parent kinds for arrow, function and generator expressions look right.
    • The describe.each(..)(..) table exclusion works, and so does the as const exclusion.
    • The top-level it/test program subject looks right.
    • I compared these against the expected counts in tests/test_model_rule_files.py, and they agree.
  • Deleted ts_/tsx_no_namespace_import rules and their rule-tests: nothing else in the repo still refers to them.
  • Prose removals in typescript-style: each removed line maps to a linter in template-typescript, as the PR table says. The new catch sentence covers a real gap: no-empty treats a block that holds only a comment as non-empty.

Known limits, not bugs. The PR already lists them as follow-ups:

  • A comment outside any function is judged with state: local, so the model doesn't see the code next to it.
  • The rules have no fixtures or evals yet.
  • Every threshold is still the unfitted 0.5.

I couldn't run the test suite in this environment, so the selection counts are checked by reading, not by running.

🤖 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: 4f668463d6

ℹ️ 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 added a commit to furedea/template-typescript that referenced this pull request Nov 15, 2026
## 概要

vitest 以外のテストフレームワークの利用を oxlint で禁止します.furedea/agent-config#195 の不安定な
ast-grep ルール `ts_no_other_test_framework` を置き換えるものです.

- `no-restricted-globals`: グローバルの `jest` を禁止(スコープを考慮するため,ローカル変数・引数・分割代入の
`jest` は報告されません)
- `no-restricted-imports`:
`jest`,`@jest/globals`,`mocha`,`chai`,`sinon`,`jasmine`,`ava`,`tape`,`node:test`
の import を禁止(メッセージは vitest の利用を促すもの)

Refs furedea/agent-config#74

## 検証

- 使い捨てファイルで確認(確認後に削除済み)
  - グローバルの `jest.fn()` は報告される
  - 引数・分割代入の `jest` は報告されない
  - `@jest/globals` と `node:test` の import は報告される
- `pnpm run check`(format,lint,typecheck,test,knip,audit)が成功

## 計画からの変更点

なし

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

---------

Co-authored-by: furedea <132188853+furedea@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 15, 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


P2 Badge オプション形式の expected failure も選択してください

test("repro", { fails: true }, () => { ... }) は Vitest が正式にサポートする expected-failure 指定ですが,function が単なる test なのでこの正規表現には一致せず,削除条件を示すコメントがなくても審査されません.Vitest では boolean option とチェーン形式が同等なので,it/test の options に fails: true がある呼び出しも対象にしてください.Vitest Test Options

ℹ️ 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".

…domness rule

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

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

What I checked (read-only, by reading the code):

  • The 8 new jev-lint rules in model-rules/typescript/. Their rule: selectors give the subject counts that test_typescript_rules_select_the_functions_they_ask_about expects:
    • describe.each(..)(..) is counted, and the inner table call is excluded.
    • as const is excluded.
    • <T> assertions are TypeScript only, through the singular language: key, which the other rules also use.
    • The stopBy on nested functions stops a throw, comment or clock read from being counted twice.
  • The deleted ts_/tsx_no_namespace_import rules and their rule-tests: nothing else in the repo refers to them.
  • The prose removed from typescript-style (any, empty catch, floating promises, knip, oxfmt, ls-lint, import type and cycles) is the part the PR says existing linters cover. The rest is kept or reworded.

P3 (inline): comment-explains-why, expected-failure-returned-as-value and inject-time-and-randomness select an arrow function or function expression only when its direct parent is in a fixed list. Functions under export default, an assignment, a ternary, or a satisfies/parenthesized wrapper are never checked. The rules are advisory, so this does not block the merge.

I could not run the tests in this environment (command approval was denied), so the expected counts were checked by reading, not by running them.

🤖 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: 3e46aed060

ℹ️ 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 commented Nov 15, 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: 3e46aed060

ℹ️ 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 24d1a3e into main Nov 15, 2026
44 of 48 checks passed
@furedea
furedea deleted the feat/migrate-typescript-style-rules branch November 15, 2026 14:19
furedea-agent Bot pushed a commit that referenced this pull request Nov 15, 2026
Add the stability criteria and the evidence from PRs #192-#195 to ADR-0021,
point rule authors to it from sgconfig.yml, and make the skill layout test
ignore hidden directories such as an untracked agents/skills/.claude.

Refs #74
Refs #196

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
furedea added a commit that referenced this pull request Nov 15, 2026
Refs #74
Refs #196

## 概要

ADR-0021 に「Which rules ast-grep may block」の節を追加し,blocking な ast-grep
規則に求める基準を記録した.

- blocking な ast-grep 規則は,1
つの構文要素を局所的に,信頼できる形で判定しなければならない.次のどれかが必要な規則は,言語自身の linter / compiler /
test runner(あれば),なければ jev-lint に任せる.
  1. ファイル外の情報(設定,`conftest.py`,他のモジュール)
  2. データの流れや実行の順番(代入,スコープ,クラス階層)
  3. 文法や式を正規表現で解析すること(`cfg(...)`,文字列の中身)
  4. 同じ意味の書き方が多いこと(YAML の引用符・flow / block 形式,import の別名)
- 根拠として,#192〜#195 のマージ済み PR 本文の「ast-grep から外した規則と理由」の表から,指摘 8 件以上の 12
規則を表にした(規則,指摘数,型,行き先).
- `agents/hooks/lint/sgconfig.yml` の先頭に,この節への 1 行の案内をコメントで追加した.
- `tests/test_workflow_skill_layout.py`: 追跡されていない
`agents/skills/.claude/` が skill として読まれ,環境によって失敗する問題を直した.`.` で始まる名前を
`SKILL_NAMES` から除外する(`skill_names()`,先にテストを追加して失敗を確認).

## 補足

- #194 は作成時点で未マージのため,ADR の #194 の 3 行は暫定と明記した(レビュー指摘).
- 依頼文では「外した規則は 11〜34 件」とあったが,PR 本文の表には 1〜8 件の規則もある(#193 の Rust など).表には 8
件以上のものだけを載せ,それ未満は「同じ PR 本文に載っており,同じ型に当てはまる」と ADR に書いた.ブロックのまま残った規則は 3
件以下(#194 の Bash / GitHub Actions は 3〜7 件で,見逃しは #196 に送った)と書いている.
- 指摘数は各 PR 本文の記載値をそのまま使った(再集計していない).

## 検証

- `uv run pytest tests/test_workflow_skill_layout.py`: 61
件成功(新規テストは,実装前に `NameError` で失敗することを確認).
- pre-commit(ruff,ty,shellcheck,commitlint ほか)通過.`dprint fmt` 済み.

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

---------

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 15, 2026
## 概要

jev-lint のモデルルールのテストが CI で一度も実行されていなかった問題を修正します.

## 原因

- `tests/test_model_rule_files.py` の `subjects_by_rule`
が,初期の3ルール(`RULE_IDS`)だけに絞り込んでいました.#190〜#195 で追加したルールは dry-run
の計画に出ていても集計から落ち,ローカルでは `KeyError: 'main-is-thin'` などで 4
件が失敗していました.ルール側(72 ルール,エラー 0)に問題はありません.
- テストは `skipif(shutil.which("jev-lint") is None)` で,CI の test ジョブは
jev-lint を PATH に置いていなかったため,失敗は黙って skip されていました.

## 修正

- 絞り込みをやめ,全関数・全コメントに当たる `function-single-purpose` と
`no-comment-restating-code` だけを除外します.
- `needs_jev_lint` マーカーと `tests/conftest.py` のフックを追加しました.jev-lint がなければ
skip し,`REQUIRE_JEV_LINT=1` なら fail します(`REQUIRE_AST_GREP` と同じ形).ガード自体は
`tests/test_jev_lint_guard.py` で検証しています.
- CI の test ジョブで `nix build .#jev-lint` の `bin` を PATH
に追加し,`REQUIRE_JEV_LINT: "1"` を設定しました.
- `tests/test_model_rule_files.py` が元から 500 行を超えていたため,サンプル定数を
`tests/model_rule_samples.py` に移しました.

## 検証

- jev-lint を PATH に入れ `REQUIRE_JEV_LINT=1` を付けた全テスト: 5186 件 pass,1 件
skip.
- `ruff check` / `ruff format --check` / lefthook: pass.
- `nix build .#jev-lint` はローカルで成功.
- CI の test ジョブで,新しいステップと `REQUIRE_JEV_LINT` 付きの実行を確認します.

Refs #74

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

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
## 概要

#196 に溜まった指摘を,main に残っている blocking(`severity: error`)の ast-grep
規則に絞って整理し,規則内の局所的な 1 構文の確認で直せるものを直した.#74 の一部.

分類は次のとおり.

- **a**:blocking 規則の見逃し・誤検出(規則が main に残っている)
- **b**:jev-lint model rule の指摘(保留中の検証用に残す.変更しない)
- **c**:obsolete(規則が削除・置換済み)
- **d**:hook・文章・インフラ

ADR-0021 に入れる基準(#214)は未マージのため,指示された基準をそのまま適用した.局所的な 1
構文(固定名,文字列の接頭辞,ノード種別 1
つの追加)なら規則を直す.ファイル外の情報,データフロー・スコープ,入れ子の文法の正規表現,同義の書き方を追い続ける修正が必要なものは,規則を継ぎ足さない.

## a.blocking 規則(fixture を先に足して修正)

| 項目 | 分類 | 対応 |
|
---------------------------------------------------------------------------------------------
| -------- |
------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| `go_no_generated_mocks`:`// Code generated by ...` ヘッダーだけの生成 mock | a
修正 | ヘッダーの接頭辞(MockGen / mockery / counterfeiter / moq / minimock)を検出 |
| `go_no_context_in_struct`:`*context.Context` のフィールド | a 修正 |
`pointer_type` を 1 種類追加 |
| `go_use_slog`:receiver・名前付き戻り値による `log` のシャドー | a 修正 | 引数と同じ判定を
receiver・result にも適用 |
| `rs_no_mocking_library`:`automock` クレート,`pub use`,`use
{mockall::automock};` | a 修正 | クレート一覧と `use` の接頭辞を拡張 |
| `rs_no_mocking_library`:`cfg_attr` 分岐が入れ子の属性を正規表現で読む(#196 最後のコメント) | a
修正 | 正規表現をやめ,`cfg_attr` の引数トークン(カンマの直後の識別子)をノードで判定 |
| `bash_readonly_constant_name`:`declare -r` を検査しない | a 修正 | スクリプト直下の
`declare -r` / `typeset -r` と,関数内の `declare -gr` を追加 |
| `bash_readonly_constant_name`:関数内の `readonly` を一律に除外 | a Limits | 既存の
`local` を固定するだけの `readonly` と区別するにはスコープ解析が要るため,除外のまま規則の Scope
に記録した(レビュー指摘で一度検査に変えたが戻した) |
| `py_pydantic_base_model_only_in_frozen_base`:`pydantic.v1` 経由の回避 | a
修正 | `pydantic.v1` の素の書き方を追加 |
| `go_use_slog`:関数内のローカル変数による `log` のシャドー | a Limits |
スコープ解析が要る.規則の本体は精度が高く,demote すると `log.Printf` を止められなくなるため,blocking
のまま規則の Limits に記録した |
| `go_iota_enum_typed`:`iota + 1` などの式 | a Limits | `1 << (10 * iota)` と
`iota + 1` は型なし定数の標準的な書き方で,構文だけでは enum と区別できない.既存の valid fixture
のとおり対象外のまま,理由を規則に記録した |
| `rs_no_follow_links`:import 別名,途中で別の型に変換するチェーン | a Limits |
別名はバインド解析が要る.変換するチェーンは該当する API を確認できていない.規則の Limits に記録した |
| `py_no_pytest_asyncio`:別名 `pytest` 経由 | a Limits | バインド解析が要る.規則の
Limits に記録した |
| `gha_job_timeout_minutes`:`jobs` 自体が flow mapping | a Limits | 実在の
workflow では使われない書き方.規則の Scope に記録した |
| `gha_workflow_permissions_deny_all`:ルート全体が flow mapping | a Limits |
同上 |
| `gha_pinned_uses_version_comment`:`action.yml` 内の tag 参照 | c | 規則は
`action.yml` を対象に含んでいる.tag 参照は対象外と Scope に書いてある設計どおり |
| `go_context_param_named_ctx` / `go_no_context_in_struct`:import
path・エイリアスの確認 | c | 規則が標準 `context` を別名なしで import したファイルに限定済み |
| `go_no_generated_mocks`:`//go:generate` 経由の mock | c | 規則が検出済み |

「a Limits」は,構文だけでは判定できない見逃しの端のケースで,規則は demote せず,規則ファイルの `Limits:`(または
`Scope:`)に記録した.精度の高い規則は,見逃しを記録して残す.誤検出が繰り返し出る規則だけを demote する.この方針は
ADR-0021 の「Which rules ast-grep may block」に 1 行足した.

## c.obsolete(規則が削除・置換済み)

main に該当の規則が無いため,対応不要.

-
TypeScript:`ts_no_unvalidated_json_cast`,`ts_catch_rethrow_requires_cause`,`ts_no_other_test_framework`,`ts_no_vague_name`,`ts_no_home_dir_in_tests`
と各 `tsx_` 版(oxlint・jev-lint へ移行)
-
Python:`py_async_test_anyio_marker`(削除),`py_pydantic_validate_json`,`py_plain_class_slots`(jev-lint
へ降格),`py_frozen_base_model_config`,`py_frozen_base_model_no_override`,`py_definition_order`,`string-literal-is-named-constant`
の `parent:` の件
-
Go:`go_sealed_interface_sumtype_decl`,`go_error_no_capitalized_message`
- Rust:`rs_unit_test_in_test_module`(clippy
へ置換),`rs_no_path_from_format`(jev-lint
へ降格),`rs_fs_call_needs_context`,`rs_no_get_prefix`
- Bash /
Actions:`gha_workflow_concurrency`,`gha_workflow_default_shell`,`bash_strict_mode_header`(jev-lint
へ降格)

## b.jev-lint model rule の指摘(変更しない)

保留中の fixtures・eval・しきい値の当てはめで扱う.#196 のコメントに記録済みで,この PR では触れない.

-
`no-exposed-mutable-collection`,`no-comment-restating-code`,`no-reaching-through-collaborators`,`construction-separate-from-execution`,`function-single-purpose`(#191,4
言語)
-
`error-handled-once`(#190),`fixture-justified`,`frozen-model-subclass-keeps-locked-settings`,`json-parse-uses-model-validate-json`(#192)
- Rust の advisory
規則:`conversion-and-query-names-follow-rust-convention`,`serde-types-follow-config-conventions`,`public-types-protect-invariants`,`domain-states-are-enums`,`paths-are-joined-not-formatted`(#193)
- Bash / Actions の advisory 規則(#194),TypeScript の advisory 規則(#195)
- `test_main_is_thin_selects_func_main_of_package_main` が
`command-query-naming` に指摘される件(誤検出と見ている.model rule の判定の話)

## d.hook・文章・インフラ

| 項目 | 分類 | 対応 |
|---|---|---|
| worktree の未追跡 `agents/skills/.claude/` を skill
と読み,`tests/test_workflow_skill_layout.py` が失敗する | d 解決済み | main
に同じ修正が入っていた(#216 の rebase で採用) |
| Stop の `SUBJECT_CAP`(20)で判定が漏れないようにする | d 解決済み | 現在は 250
で,実測の上限を下回らないことをテストが保証している |
| 後段の review が失敗すると,同じ指摘で毎ターン Stop を block する | d 修正 | 完了した前段の結果をレシートの
`resume` に保存し,失敗した tier だけを再実行する.通知済みの件数(`shown`)も保存し,同じ指摘では二度 block しない
|
| 後段の review の失敗理由が捨てられ,`incomplete` としか出ない.`skipped_files=1` が実数でない | d
修正 | `Judgement.failure_reason` を結果の行に出し,`skipped_files` は失敗した review
のファイル数にした |
| 2 tier の review の順序(調整済み committed,調整済み uncommitted,未調整 committed,未調整
uncommitted)のテストが無い | d 修正 | `test_model_rules_resume.py` に順序のテストを追加 |
| `scripts/bootstrap_server.sh` が ast-grep を入れない | d 修正 | ast-grep
0.42.1 を sha256 付きで固定し,dprint と同じ zip の経路で入れる(`install_zip_tool`).bats の
fixture,Renovate の確認,README を更新 |
| `.bats` を ast-grep で Bash として読めるか | d 対応しない | `languageGlobs`(`bash:
["*.bats"]`)で読めることは確認したが,Bash の規則は `.bats` に有効化しない.`@test` ブロックは Bash
の文法ではなく,読めても `readonly` や関数名の規則が意図しない形で当たる.hook の `EXTENSIONS`
と整形の対象も広がる |
| `severity: error` を hook の block 判定に結びつける | d 範囲外 | #203 の範囲 |
| Rust `tooling.md` の package-level guard,Go の `t.Parallel()` の文章 | d
対応しない | テンプレートの linter が既に覆っているため,文章は戻さない |
| `types.md` の `to_owned()` / `String::from`,`package_design.md` の
`pub`,`types.md` の exhaustive match,`errors.md` の `# Panics` の文章 | d
対応しない | 同上(テンプレートの linter が覆う分は戻さない) |

## 検証

- ast-grep の規則テスト:28 件通過,bats:81 件通過(ast-grep の固定を追加)
- `uv run pytest`:5198 件通過,4 件失敗.失敗はいずれも model rule の subject
選択テスト(`test_main_is_thin_selects_func_main_of_package_main` など)で,この PR
を外した main でも同じく失敗する(この環境での既存の失敗.CI の `test` job は通る)
- `ruff check` / `ruff format --check` / `ty`:通過

Refs #74, #196

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

---------

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 19, 2026
## 概要

TypeScript の jev-lint 規則 16 件を fixtures で測り,cutoff を仮の 0.5 から fitted
midpoint に置き換える.#196 の TypeScript 向け指摘(PR #195 由来の 11 項目)を matcher と
state に反映する.規則はすべて advisory のままで,style skill
の文章も残す(親の指示:今回は昇格と文章削除をしない).

## 変更

- **matcher・state(#196)**
  - `repeated-cases-use-it-each`:Vitest の `suite(...)` も選ぶ.
- `inject-time-and-randomness`:`Date()` と括弧なしの `new Date` も選ぶ.`state:
located` にし,criteria の false 側に「`node:crypto` / Web Crypto
由来でない同名ヘルパー」を加えた.
-
`comment-explains-why`・`expected-failure-returned-as-value`・`inject-time-and-randomness`:アロー関数・関数式は親(`pair`,`export_statement`,`jsx_expression`,代入,配列,三項演算子など)を問わず
subject にする.
- `expected-failure-returned-as-value`:`Promise.reject(...)` も選び,ask /
criteria を「throw または rejected promise」にした.
- `states-modeled-as-discriminated-union`:クラスのフィールド(optional,boolean
型,`= true/false`)で状態を持つクラスも選ぶ.
-
`type-assertion-follows-validation`・`angle-bracket-assertion-follows-validation`・`mock-only-external-boundaries`・`comment-explains-why`:`state:
located`.
- matcher テスト:`tests/model_rule_samples.py` と
`tests/test_model_rule_files.py` の件数(旧規則では 5 規則の件数が合わないことを確認).
- **fixtures**:fixtures の無かった 14 規則に
`fixtures/violating.ts|conforming.ts`(テスト系は `.test.ts`)と `expect.yml`(各
bad 4・clean 4,境界寄りの例を含む).ラベルの行がすべて matcher に選ばれることを ast-grep で確かめた.
- **cutoff**:16 規則とも jev-lint の fitted midpoint に置き換え,根拠(件数,最高の
clean,最低の bad,最悪 pass の値)を `threshold:` の上のコメントに書いた.境界の fixture が無く
replay が blind と判定した 8 規則には `inconclusive:` で理由を宣言した.
- `baseline.json`:ユーザーが実行した `jev-lint eval --accept` の記録(3 passes).

## fit の結果(3 passes,平均.括弧内は最悪 pass)

ask / criteria は書き直していない:16 規則とも平均でも最悪 pass でも clean と bad が分かれた(#220
の「分離しない規則は書き直す」に当たる規則が無い).そのため追加の eval は依頼していない.

| ルール | 旧 cutoff | 新 cutoff | 最高の clean | 最低の bad | 0.5 での fp / fn | 判定
|
| --- | --- | --- | --- | --- | --- | --- |
| `angle-bracket-assertion-follows-validation` | 0.5 | 0.55 | 0.23
(0.25) | 0.86 (0.85) | 0 / 0 | blind |
| `command-query-naming` | 0.79 | 0.81 | 0.70 (0.71) | 0.91 (0.90) | — |
— |
| `comment-explains-why` | 0.5 | 0.42 | 0.10 (0.11) | 0.75 (0.73) | 0 /
0 | blind |
| `construction-separate-from-execution` | 0.5 | 0.66 | 0.32 (0.36) |
0.96 (0.95) | 0 / 0 | blind |
| `error-message-names-operation` | 0.75 | 0.74 | 0.49 (0.52) | 0.96
(0.96) | — | — |
| `expected-failure-returned-as-value` | 0.5 | 0.86 | 0.72 (0.77) | 0.94
(0.94) | 3 / 0 | — |
| `function-single-purpose` | 0.5 | 0.38 | 0.18 (0.19) | 0.59 (0.57) | 0
/ 0 | — |
| `inject-time-and-randomness` | 0.5 | 0.8 | 0.62 (0.64) | 0.96 (0.96) |
1 / 0 | — |
| `known-defect-marker-names-removal` | 0.5 | 0.49 | 0.13 (0.15) | 0.84
(0.82) | 0 / 0 | blind |
| `mock-only-external-boundaries` | 0.5 | 0.59 | 0.34 (0.35) | 0.84
(0.83) | 0 / 0 | blind |
| `no-comment-restating-code` | 0.5 | 0.53 | 0.13 (0.15) | 0.92 (0.91) |
0 / 0 | blind |
| `no-exposed-mutable-collection` | 0.5 | 0.93 | 0.89 (0.91) | 0.95
(0.95) | 1 / 0 | 余白が狭い |
| `no-reaching-through-collaborators` | 0.5 | 0.65 | 0.48 (0.51) | 0.80
(0.79) | 0 / 0(1 件が pass ごとに 0.5 をまたいだ) | — |
| `repeated-cases-use-it-each` | 0.5 | 0.25 | 0.08 (0.09) | 0.43 (0.41)
| 0 / 1 | — |
| `states-modeled-as-discriminated-union` | 0.5 | 0.35 | 0.09 (0.10) |
0.61 (0.59) | 0 / 0 | blind |
| `type-assertion-follows-validation` | 0.5 | 0.54 | 0.21 (0.22) | 0.87
(0.86) | 0 / 0 | blind |

新 cutoff では 16 規則とも tp 4(`command-query-naming` は 8)・fp 0・fn 0.`jev-lint
eval --replay` は 16 suite すべて通る.

## 昇格の候補(今回は昇格しない)

ADR-0021 の条件(fixtures で fp 0)はすべて満たすが,各 8 件程度で較正とは言えない(ADR-0020).また Stop
hook は `--fail-on error` の非ゼロ終了を実行失敗として扱うため,`severity: error` にすると
finding が隠れる(親の指示).最悪 pass でも clean と bad の差が 0.3 以上ある規則を候補とする.

| 候補 | 消せる文章(`agents/skills/typescript-style/references/`) |
| --- | --- |
|
`type-assertion-follows-validation`,`angle-bracket-assertion-follows-validation`
| types.md「Do not use `as` casts except immediately after validation, as
in the brand example above.」 |
| `comment-explains-why` | code_style.md「Comments explain why, not
what.」 |
| `known-defect-marker-names-removal` | testing.md「Record a reproduced
defect with Vitest `test.fails` and a comment naming the condition for
removing it; …」のうち comment の部分 |
| `mock-only-external-boundaries` | testing.md「Prefer fake
implementations over mocks. Use `vi.mock` only for external dependencies
at module boundaries.」 |
| `states-modeled-as-discriminated-union` | types.md「Model states and
kinds as discriminated unions with a tag field, not optional fields or
flags.」 |
| `inject-time-and-randomness` | testing.md「Inject time and randomness
as arguments …」 |
| `repeated-cases-use-it-each` | testing.md「Use `it.each` for the same
behavior across multiple inputs.」 |
| `error-message-names-operation` | errors.md「The message names the
operation and subject.」 |

候補外(余白が狭い):`expected-failure-returned-as-value`(errors.md の「Return
expected failures as values …」「`throw` only for programmer errors
…」),`no-exposed-mutable-collection`,`no-reaching-through-collaborators`,`command-query-naming`.

### AGENTS.md(共有の文.このレーンでは編集しない)

AGENTS.md の規則は言語をまたいで共有されるので,全言語のレーンで昇格がそろったときだけ消せる.TypeScript
側で候補になったのは以下:

- `construction-separate-from-execution` →「Separate object
creation/configuration from execution logic.」
- `function-single-purpose` →「Keep functions single-purpose at one
abstraction level, with short variable lifetimes.」の前半
- `no-comment-restating-code` →「Minimize comments and docstrings; …」

`no-exposed-mutable-collection`(「do not expose mutable raw
collections」),`no-reaching-through-collaborators`(「Law of
Demeter」),`command-query-naming`(「name command functions for their side
effects …」)は TypeScript では候補外.

## 測定

- **eval の費用**:`eval --dry-run` で,TypeScript 16 suite を 3 passes 回すと約
0.0089 USD(約 211k input tokens).`--accept` は 1 回だけ実行した.
- **Stop 1 回あたりの subject 数**(`jev-lint review --dry-run`,全 model
rules,未コミットの変更として計測)
- TypeScript fixtures 30 ファイル・1123 行:415 subjects,51 requests,0.0087
USD(100 行あたり約 37 subjects).
  - matcher テストのサンプル 101 行:47 subjects,2 requests,0.00092 USD.
- **上限 250 との関係**:fixtures は関数が詰まっているので,実際のコードより密度が高い.この密度でも 250
subjects は約 675 行の TypeScript 変更に当たり,費用は約 0.005 USD.ADR-0021 の見積もり(上限時 約
0.006 USD)と食い違わず,250 を変える根拠は出なかった.このリポジトリには TypeScript
のコードが無いので,実際のセッションでの値は取れていない.

## 確認

- `jev-lint rules`:16 規則,エラー 0.
- `jev-lint eval --replay`:TypeScript 16 suite すべて通過.
- `uv run pytest tests/test_model_rule_files.py
tests/test_agents_md_model_rules.py
tests/hooks/test_model_rule_fixtures.py`:29 passed.
- 全体の pytest は Stop の検証で実行済み.baseline を追加する前の失敗は
`test_every_saved_eval_baseline_still_scores_as_accepted`(新しい suite に
baseline が無い)の 1 件だけで,baseline 追加後に通過.
- CI の linter で TypeScript を見るものは無い(ls-lint は `.ts` / `.test.ts` で通過).

## Limits

- fixtures は各 8 件程度で,このレーンで書いたもの.較正ではなく,境界の fixture は今後の課題(blind の 8
規則).
- `no-exposed-mutable-collection` は「不変条件の無いデータ record が自分の配列を返す」clean
の例が 0.89 で,余白は 0.04 しかない.criteria の例外の書き方が弱い可能性があるので,rule.yml のコメントで
cutoff を暫定値と明記した(review 指摘 P3).
- `states-modeled-as-discriminated-union` のクラス分岐は,フィールド全体のテキストに regex
を当て,入れ子のクラスまで探す.そのため,初期化式の中に `= true` があるフィールドや,内側のクラスのフィールドでも外側のクラスが
subject になる(review 指摘 P2).余分な subject
と誤検出が増えるだけで見逃しは起きないので,このレーンでは直さない.`value` / `type`
の子に限定し,負のサンプルを足すのは後の変更で行う.
- `inject-time-and-randomness` の criteria の除外文(`node:crypto` や Web
Crypto API から import していない同名の呼び出しは違反ではない)のせいで,import なしで使えるグローバルの Web
Crypto
の呼び出し(`crypto.randomUUID()`,`crypto.getRandomValues(...)`)を見逃すおそれがある.fixtures
にもこの形の例が無い(再レビュー指摘 P2.レビュー対応は 1 巡までの方針と,規則が advisory
であることから,このレーンでは直さない).除外を「名前を覆い隠すプロジェクトのヘルパー,または注入された
`rng`」に限り,グローバル呼び出しの bad 例を足して refit するのは後の変更で行う.
- `comment-explains-why`(style skill 由来)と
`no-comment-restating-code`(AGENTS.md 由来)はほぼ同じことを判定している.統合は範囲外.
- `jev-lint review` は本文が同じ subject を 1 件にまとめる(matcher
テストのサンプルでは文言を変えて回避した).
- `docs/DESIGN.md` の「Model Rules at Stop」の「Five cutoffs are fitted …;
the others … stay at the 0.5 starting value」は,この PR で TypeScript
について古くなる.共有の文書で他レーンと衝突するので,親が全レーンの後で直す前提で編集していない.

Refs #220

🤖 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