Skip to content

docs(hooks): document session modules and privatize internal helpers - #131

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

furedea merged 1 commit into
mainfrom
docs/dn-a-session-docstrings

Conversation

@furedea-agent

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

Copy link
Copy Markdown
Contributor

概要

#74 段階 1B の ruff D(google)と N の有効化に向けた,レーン dn-a の準備です.対象は agents/hooks/lib/ の session_store.py,session_gate.py,herdr_ownership.py,provider_adapter.py の 4 ファイルで,pyproject.toml は変更しません(有効化は最後の PR で行います).

対象 4 ファイルは,目標設定(D,N を選択し,pydocstyle は google,D104 D105 D107 を無視)で ruff の指摘が 0 件になりました.

方針

  • 自モジュール内だけで使う名前は,docstring で埋めずに先頭 _ の private にしました.git grep で agents/,scripts/,tests/ に外部の利用がないことを確認しています.
  • 他モジュールやテストが使う公開 API には,名前だけでは分からない契約(返す値,拒否する入力,副作用)を docstring に書きました.
  • 既存の docstring とコメントは削っていません.

内訳(指摘 68 件)

ファイル private 化 docstring を追加
session_store.py 8 14
session_gate.py 8 2
herdr_ownership.py 17 1
provider_adapter.py 15 3
合計 48 20

herdr_ownership.py では,docstring が既にあった _require_closable と _require_owned_workspace も,同じ理由(外部の利用なし)で private にしました.

private 化した名前と根拠

外部の利用がないことは git grep -w で確認済みです.

  • session_store.py: _create_record,_atomic_bytes,_acquire_lock,_prune_records,_trusted_record_directory,_log_files,_prune_record,_remove_if_expired
  • session_gate.py: _verify,_current_status,_save_skip,_bounded_summary,_valid_receipt,_check_identity,_check_budget,_notification.外部(verification_session.py とテスト)が使うのは gate,status,unresolved だけです.
  • herdr_ownership.py: _record_result,_is_single_call,_target,_option_value,_record_workspace,_require_closable,_require_removable,_require_owned_workspace,_expire_workspace,_live_panes,_matches_live,_valid_entry,_normpath,_claim,_require_owned,_agent_session,_matches_agent,_save,_live_agents.外部が使うのは check,confirm,entries,live_path,herdr_result です(cleanup_worktrees.py とテスト).
  • provider_adapter.py: Adapter._native,_audit,_fan_out,_shell,_harness,_check_paths,_content(dispatch 経由でだけ呼ばれる),および _shared_directory,_secret_policy_path,_command_text,_edit_targets,_command_paths,_secret_path_refusal,_secret_path_reason,_usage_entry.main,dispatch,normalized,translated,lint(テストが使う)と no_cwd,system_message,additional_context,system_message_output,Adapter,Profile(各 provider の hook_adapter.py が使う)は公開のままです.

docstring を書いた公開 API

SessionRecord(baseline,results,save_results,end,write_log,lock),state_directory,worktree_id,session_directory,load,private_directory,read_json,atomic_json,record_directories,VerificationRun.configuration_failure,unresolved,entries,no_cwd,Adapter.main,Adapter.dispatch.

検証

  • 目標設定での ruff(対象 4 ファイル): 0 件
  • ruff check,ruff format --check,ty check: 通過
  • pytest -n auto: 4531 passed,1 skipped

Refs #74

🤖 Generated with Claude Code

Prepare session_store, session_gate, herdr_ownership and provider_adapter
for ruff D (google) and N. Names used only inside their own module become
private; the rest get docstrings that state the 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
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-10T13:49:55.656788Z
We couldn’t complete this review. Comment @codex review to try again.
0b95641 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 findings (P0: 0, P1: 0, P2: 0, P3: 0)

This PR renames module-local helpers to private names and adds docstrings across 4 files under agents/hooks/lib/. It does not change behavior.

What I checked:

  • Rename coverage: I searched agents/, tests/ and scripts/ for every renamed name, looking for module-attribute access (store.X, herdr_ownership.X, session_gate.X, provider_adapter.X), from … import lists, string-based monkeypatch.setattr and mocker.patch targets, and getattr. Nothing outside these modules uses a renamed name. External callers only use names that are still public: gate, status, unresolved, check, confirm, entries, live_path, herdr_result, register, load, record_directories, file_lock, private_directory, worktree_id, Adapter.dispatch, Profile and so on.
  • Adapter methods: No provider hook_adapter.py subclasses Adapter or overrides the renamed methods. Tests reach them only through dispatch, and its table now points to the private methods.
  • Docstrings: I spot-checked them against the code (main exit codes, private_directory, configuration_failure, unresolved). They match.

No new tests are needed, since nothing changes at runtime.

🤖 Generated with Claude Code

@furedea
furedea merged commit feadc8d into main Nov 10, 2026
22 of 24 checks passed
@furedea
furedea deleted the docs/dn-a-session-docstrings branch November 10, 2026 14:25
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