Skip to content

docs(hooks): document the public API of hooks/lib and privatize internals - #130

Merged
furedea merged 1 commit into
mainfrom
docs/dn-b-lib-docstrings
Nov 10, 2026
Merged

furedea merged 1 commit into
mainfrom
docs/dn-b-lib-docstrings

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

概要

ruff の D (google) と N を有効化するための準備です(#74 stage 1B の持ち越し分).agents/hooks/lib/ のうち担当ファイルを,pyproject.toml を変更せずに D/N 違反ゼロにします.

対応内容

区分 件数 方針
private 化 38 モジュール内だけで使われる名前を _ 始まりにし,モジュール内の呼び出しを更新
docstring 追加 23 他モジュールまたはテストが使う公開 API に契約を記述
表記修正 2 ctime を大文字始まりに,バックスラッシュを含む docstring を raw 文字列に

private 化と根拠

git grep -nw を agents/ scripts/ tests/ に対して実行し,定義元モジュール以外にヒットがないことを確認しました.

  • automation_paths: stays_inside
  • command_objections: is_pinned_call
  • command_policy: validate_rule, is_name_list, all_patterns
  • formatter_policy: js_config_tool
  • git_safety: git_reason, full_option
  • herdr_grammar: any_word, number, one_of, accepts
  • powershell_options: is_powershell, is_with_args
  • secret_path_policy: normalize, candidate(_is_candidate)
  • session_snapshot: is_confined
  • shell_input: redirected_inputs, stdin_operator, reads_process_substitution, static_script, computed_input
  • shell_inspection: is_plain_quoted, text_without_nodes, outermost_spans, plain_pipeline_statement
  • shell_syntax: statement_writes, redirect_operator, is_foreign_shell, foreign_option_indexes
  • shell_wrappers.OptionScan: flags, valued, take_value, value_at, refuse
  • trusted_owners: origin_repository, cached_answer, remember

docstring を付けたもの

  • command_objections.Policy の 3 プロパティ,command_policy.prefix_reason
  • herdr_grammar.is_watch_command / has_global_option
  • hook_decision.ask / deny,patch_input.paths / added_text
  • secret_path_policy.load / blocked_rule
  • session_snapshot.Snapshot の digest / changed_paths / to_json / from_json
  • shell_input.InputSources.of,shell_syntax.Command.has_dynamic_words / program_is_dynamic
  • shell_wrappers.OptionScan.run
  • trusted_owners.TrustedOwners / declares,github_answer(テストが monkeypatch で差し替えるため公開のまま)

名前の言い換えではなく,拒否する入力・例外・副作用・非自明な制約を書いています.

対象外(最終の有効化 PR で対応)

  • check_selection.UnknownTestCommand の N818(brief の指示どおり持ち越し)
  • shell_syntax.Command.__post_init__ の D105(目標設定で ignore)

検証

  • ruff check --select D,N --ignore D104,D105,D107 + google convention(担当ファイル): UnknownTestCommand の N818 のみ
  • ruff check / ruff format --check / ty check: 通過
  • pytest: 4531 passed, 1 skipped

Refs #74

🤖 Generated with Claude Code

@furedea

furedea commented Nov 10, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-10T14:13:30.127858Z
We couldn’t complete this review. Comment @codex review to try again.
b2134e2 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

Copy link
Copy Markdown

Review summary

No blocking findings (P0/P1: 0).

This PR does three things: it renames internal helpers to private (_ prefix), adds docstrings, and fixes two docstrings (ctime → The ctime, and a raw string for the backslash).

Verified:

  • No old name is still used anywhere in the repository, including the agents/, scripts/ and tests/ directories and monkeypatch string targets. Every new _ name is defined in the same module as its call sites.
  • OptionScan._flags / _valued are properties, not dataclass fields, so the constructor signature stays the same. The only callers are shell_syntax.py:481 and shell_wrappers.py:91.
  • github_answer stays public for monkeypatch, which is correct.
  • The Protocol property bodies keep ... after the new docstrings, so they behave the same.
  • The double_quoted_text raw docstring renders the same as before.

No logic changed, so no new tests are needed. I could not run pytest in this environment; my check relies on the grep and the diff above.

🤖 Generated with Claude Code

furedea
furedea previously approved these changes Nov 10, 2026
…nals

Prepare ruff D (google) and N for agents/hooks/lib. A name used only inside its own module
becomes private instead of getting a filler docstring; real public API states its contract.

Refs #74

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea

furedea commented Nov 10, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

Copy link
Copy Markdown

Review summary: no findings.

This PR only renames module-internal helpers to private names and adds docstrings. I didn't see any behavior change.

  • I grepped agents/, scripts/ and tests/ for every renamed name: attribute access, from ... import, and string-based monkeypatch/getattr targets. Nothing outside the defining modules still uses an old name.
  • OptionScan has no subclasses or outside users of the renamed methods. Its only callers use .run().
  • herdr_grammar.Form.flags/valued are dataclass fields, not the renamed OptionScan properties, so they were correctly left alone.
  • github_answer stays public for monkeypatching, which is correct.
  • The new docstrings match what the code does. That includes the switch to an r""" string in double_quoted_text, which shows the same text as before.

I could not run the test suite in this environment. This review is static only.

@furedea
furedea merged commit 5252cfd into main Nov 10, 2026
22 of 24 checks passed
@furedea
furedea deleted the docs/dn-b-lib-docstrings branch November 10, 2026 14:24
furedea added a commit that referenced this pull request Nov 10, 2026
## 概要

ruff の D (pydocstyle, google),DOC,N (pep8-naming) を有効化する最終 PR (#74 stage
1B の持ち越し分).設定は template-python / dotfiles と同じ形にした.先行 lane (#130, #131,
#132, #133) の修正は既にマージ済みで,この PR は残りの違反を直したうえで設定を有効化する.

`ruff check .` は有効化後の設定で 0 件.ブランチは 1 コミットで,lefthook の全フックを除外なしで通過している.

Refs #74

## 設定 (pyproject.toml)

- `select` に `D`,`DOC`,`N` を `W` と `F` の間に追加 (template-python / dotfiles
と同じ並び).`DOC` による新規指摘は 0 件を確認済み
- `ignore` に `D104`,`D105`,`D107` を追加
- `per-file-ignores` の `tests/**` に `D` を追加
- `[tool.ruff.lint.pydocstyle] convention = "google"` を追加

既存の ignore は削除していない.

## この PR での修正

### 改名 (N818)

ドメイン概念はそのまま,`Error` 接尾辞のみ追加し,agents と tests の全使用箇所を更新した.

- `UnexpandableGlob` → `UnexpandableGlobError`
- `UnsupportedSyntax` → `UnsupportedSyntaxError`
- `UnplacedCommit` → `UnplacedCommitError`
- `UnknownTestCommand` → `UnknownTestCommandError`

### 非公開化 (外部から使われないことを `git grep` で agents/ scripts/ tests/ に対して確認)

| ファイル | 件数 | 名前 |
| ---------------- | ---- |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| `guard_file.py` | 10 | `_policy_path`, `_load_policy`,
`_protected_reason`, `_validate_filename_rule`, `_commit_reason`,
`_content_match`, `_scan_content`, `_judged_commit`, `_context`,
`_session` |
| `shell_paths.py` | 1 | `_brace_words` |

### docstring を書いた公開 API

| ファイル | 件数 | 名前 | 理由 |
| ---------------- | ---- |
----------------------------------------------- |
------------------------------------------------------------------ |
| `guard_file.py` | 3 | `commit_filename_rules`, `content_text`, `main`
| テストと CLI から使われる公開 API |
| `shell_words.py` | 1 | `home_directory` |
`tests/hooks/test_shell_words.py` が直接呼ぶため非公開化しなかった |

docstring は名前の言い換えではなく,返す値・拒否する入力・例外を述べている.

## リポジトリ全体の内訳 (ac-dn の全 lane)

| PR | 非公開化 | docstring 追加 | 改名 (N818) |
| -------------------------------------------- | -------: |
-------------: | -----------------: |
| #130 (hooks/lib) | 38 | 23 | 0 (他に表記修正 2) |
| #131 (session_store ほか 4 ファイル) | 48 | 20 | 0 |
| #133 (hooks/\*.py, scripts, skills, tests) | 44 | 15 | 2 |
| #132 (verification_session, check_execution) | 8 | 7 | 0 |
| この PR | 11 | 4 | 4 |
| 合計 | 149 | 69 | 6 |

#130 と #133 の件数は各 PR 本文の表,#131 は本文の合計行,#132 は ac-dn の表 (非公開化 7 +
`collect`,文書化
`main`/`dispatch`/`failure`/`Status`/`Result`/`Result.failed`/`execute`)
による.

## 検証

- `ruff check .`: All checks passed
- `ruff format --check .`: 239 files already formatted
- `ty check`: All checks passed
- `pytest`: 手元 (sandbox) では 2 件を除き通過.失敗は
`tests/hooks/test_formatter_config.py` の dprint 統合テスト 2 件のみで,sandbox が
`plugins.dprint.dev` への通信を遮断するため (この PR の変更とは無関係).CI で確認する
- pre-commit (lefthook) は `LEFTHOOK_EXCLUDE` なしで全フック通過

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

Co-authored-by: furedea <[email protected]>
Co-authored-by: Claude Sonnet 5.5 <[email protected]>
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