Skip to content

refactor(provider): derive sync targets and hook bundle capture from the registry - #234

Merged
furedea merged 1 commit into
mainfrom
refactor/derive-provider-lookups-from-spec
Nov 12, 2026
Merged

furedea merged 1 commit into
mainfrom
refactor/derive-provider-lookups-from-spec

Conversation

@furedea-agent

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

Copy link
Copy Markdown
Contributor

概要

プロバイダ名で設定を引いていた layout.rs と generation/hook_bundle.rs を,spec の宣言から導出するように置き換えた.挙動は変えない純粋なリファクタリング.

Refs #232(秘密パスのポリシーを Codex に適用する secrets レーンが Issue を完了させる)

計画:#232 (comment)

変更内容

  • ConfigSpec に sync_target: SyncTarget を追加(SameAsRendered/File/InProfile).Hermes は .hermes/config.yaml,dsh は .dsh/profiles/<profile>/package.json,他は描画先と同じ.
  • InstalledLayout から ProviderId::Hermes/ProviderId::Dsh の参照と hermes_config を除き,generated_files_for は宣言から導出する.
  • HookSpec に bundle: BundleCapture(バンドルに含める設定ファイルと,直下のシェルスクリプトのディレクトリ)を追加.Codex だけが宣言する.
  • hook_bundle::supported_files と script_ops,Staged::scripts,shell 側のステージングを宣言から導出する.ProviderId::Codex と .codex の直書きをなくした.
  • docs/DESIGN.md の型一覧を更新.

残りの検索(報告のみ,今回は触らない)

  • generation/external_hooks.rs:CLAUDE_HOOK_FILE/CODEX_HOOK_FILE,codex_script_assets の .codex/hooks,is_codex_script
  • shell/load/bundle.rs:bundle_codex_config の .codex/config.toml,.codex 直下のスクリプト読み込み
  • generation/bridges.rs(Hermes・Pi のブリッジ資産),generation/hooks.rs(Claude),cli.rs のサブコマンド別の ProviderId

これらは取り込み側の意味(codex_config の features マージなど)に結びついており,別 Issue に切り出すのが適切.

テスト

  • installed_layout_derives_sync_targets_from_the_registry:同期先のパスとプロファイル引数の反映
  • hook_bundle_capture_is_declared_by_codex_alone:バンドル対象の宣言と supported_files の順序
  • 既存テスト(golden,nix/providers.json,レジストリの value_variants 対 PROVIDERS を含む)は変更なしで通過

検証

  • cargo test:全件成功
  • cargo clippy -- -D warnings:警告なし
  • cargo fmt --check:差分なし

🤖 Generated with Claude Code

…the registry

Declare the file a rendered config is merged into (SyncTarget) and what a hook
bundle captures besides the hook file (BundleCapture) in the spec, so layout
and hook_bundle no longer look providers up by name.

Refs #232

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

furedea commented Nov 12, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 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-12T03:54:06.003088Z 3ef44da 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
Contributor

Review summary

No blocking findings. I found no correctness, security, or test-coverage problems worth flagging.

What I checked:

  • generated_files_for / sync_targets_for: The old code always appended the Hermes and dsh sync targets. The new code only includes targets for providers in the list it's given. Production code (install, protected_paths_for_runtime) always passes the full PROVIDERS, so the output and its order (.hermes/config.yaml, then .dsh/profiles/<profile>/package.json) stay the same. Only the test-only provider subsets see a difference, which is expected.
  • supported_files: The order is unchanged: every external hook file first, then .codex/config.toml.
  • Script staging: staged_scripts and script_ops produce the same .codex/<name> copies as before. shell_scripts still filters with is_codex_script. That works today because only Codex declares a scripts directory, and the PR description already lists it under remaining work.
  • Removing hermes_config: Nothing else references it.

Minor note: the description says docs/DESIGN.md was updated, but that file isn't in this PR's diff.

🤖 Generated with Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 3ef44daf19

ℹ️ 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 bfb417e into main Nov 12, 2026
21 checks passed
@furedea
furedea deleted the refactor/derive-provider-lookups-from-spec branch November 12, 2026 03:57
furedea added a commit that referenced this pull request Nov 12, 2026
…233)

Closes #232


計画:https://github.com/furedea/agent-harness/issues/232#issuecomment-6813519563(レーン
`secrets`)
`lookups` レーンの #234 はマージ済みで,これで #232 の受け入れ条件が揃う.

## 概要

秘密パスのポリシー(`hooks/rules/secret_path_policy.json`)を Codex の
`[permissions.guarded.filesystem]` にも反映する.
これまで Codex ではフックの検査だけが効いており,フックを通らないシェルからの読み取りは設定では止まらなかった.

## 変換規則

| ポリシーのルール | Codex の値 |
|---|---|
| 読み取りを禁止する(`access` に `read` を含む) | `"none"` |
| 書き込みのみ禁止(`access` が `["write"]` だけ) | **Codex には出さない**(警告もしない) |

- `~/` と `//x`(絶対パス)はトップレベルのキー,相対パターンは
`[permissions.guarded.filesystem.":workspace_roots"]` の下に置く.
- 先頭が単独の `/` は Claude ではプロジェクト相対で曖昧なのでエラー.`/` を含まない相対パターン(`.env*`)は
`**/` を前置して任意の深さに一致させる.
- 保護パス(ハーネス自身のファイル)のエントリ(`"read"`)は変えない.

### 書き込みのみのルールを Codex に出さない理由

- Codex のファイルシステム権限は,エージェントが起動する**すべてのプロセス**に効く.Claude の `Edit(...)` の
deny は Edit ツールにしか効かない.
- 書き込みのみのルールが守るのは,ハーネスのスクリプト自身が書き込む状態である.たとえば `verification_session.py`
は `**/agent-harness/{verification,trusted-owners,audit}/**` に書く.
- Codex のサンドボックスでこれらの書き込みを禁止すると,スクリプトが壊れる.フックが書き込みのみのルールを引き続き強制する.
- Claude Code のサンドボックスが,こうしたパスの読み取りは禁止し,`~/.local/state/agent-harness`
への書き込みは許すのと同じ扱い.
- 結果として,秘密パスのルールから「弱い(`"read"`)エントリ」は生成されない.弱いエントリは保護パスだけになる.

## 競合の検出(書き換えはしない)

Codex は具体的なエントリを優先する.そのため `secrets/** = "none"` の下に `secrets/key =
"read"` があると,読み取りが開く.逆に,ソースが意図的に開けた例外(`:root = "deny"` の下の `~/.codex =
"read"`)を自動で閉じるのも誤りになる.どちらの意図かを推測して書き換えると,レビューで互いに逆向きの指摘が出たため,**ガード用のエントリは書き換えず,競合を検出して生成を失敗させる**.

-
競合:厳しいエントリが,より緩いエントリを覆う組(同じパス,祖先ディレクトリ,マッチするグロブ).緩いエントリが厳しいエントリの配下にある場合だけを競合とする.厳しいエントリが緩いエントリの配下にある通常の配置(`:workspace_roots
= "write"` の下に `**/secrets/** = "none"`)は競合ではない.
- 検査する組:生成されたエントリどうし,生成されたエントリとソースの
`codex/config.toml`(`:workspace_roots`
の入れ子の表を含む).ソースどうしの組は,ソースの作者のものなので検査しない.
- エラーには,両方のエントリ,それぞれのアクセス,宣言された場所(生成側,またはソースのファイル)を出す.
- `generation/guarded_path.rs`:`GuardedEntry` は `Deny`(パターン可)か
`Looser`(正規化済みの具体的パスのみ)で,パターンを持つ `Looser`
は作れない.パスは一度だけ正規化する(`~`,`.`,重複する `/`,`..`,ドライブレター).
- `generation/guarded_conflict.rs`:上の判定を生成側とソースの表に適用する.
- グロブ照合は自前の小さな実装(`*`,`**`,`?`)にした.`globset` などを足すと `regex`
系の依存が増え,このリポジトリは依存を完全固定しているため.`[...]` と `{...}`
は取りうる範囲に広げて扱い,覆う範囲が広がる方向(より厳しい側)にだけ誤る.
- 読み取りを禁止するルールが波括弧のパターンを持つときは,Codex が波括弧を展開しないため,パターン名を示して生成を失敗させる(実際の
agent-config のポリシーに該当するルールはない).バックスラッシュは区切りとして扱う.
- 既知の制限:プロジェクト内インストール(`--runtime-root` がプロジェクト)の絶対パスの保護エントリは,ソースの
`:workspace_roots`
とは照合しない(ルールごとにルートを分けて比べるため).競合検出は安全網で,秘密ポリシーはフックが実行時に強制する.グロブどうしの包含は比べない(別のグロブより緩いグロブは検出できない).`:tmpdir`
は実行環境で決まるためモデル化していない(`:slash_tmp` は `/tmp`).`~`
は生成時にホームが分からないため記号のまま扱い,`~/x` と同じ場所を指す `/Users/.../x` は別のルートとして比べる.
- ソースがスカラーの `:workspace_roots = "write"` を持ち,生成側が入れ子の表を出すときは,マージで消えないよう
`"." = "write"` にする(意味は変えない).

## Codex のソースでの確認(根拠)

`openai/codex` の `6bfdc75f0d9e6fae313234f694839866d7c63c39`(main)を `gh
api` で読んだ.

- `codex-rs/protocol/src/permissions.rs`:`FileSystemAccessMode` は
`Read`/`Write`/`Deny`.`Deny` は `#[serde(alias = "none")]` なので **`"none"`
は受理される**.ただし「legacy input alias retained temporarily」と注記されている.同じ具体性の衝突では
`deny` が勝つ.
- `codex-rs/config/src/permissions_toml.rs`:`filesystem` 表は
`glob_scan_max_depth` と,キーごとの `FileSystemAccessMode` または入れ子の表.
- `codex-rs/core/src/config/permissions.rs`:グロブを含むキーは **`deny`
のときだけ**パターンとして扱われる.`read`/`write` のグロブは末尾の `/**` だけ許され,それ以外はエラー.非 macOS
で `**` を使う deny グロブは `glob_scan_max_depth`(すでに 5 を出力)が必要.
- `codex-rs/core/src/config/permission_path.rs`:トップレベルのキーは絶対パスか `~/...`
か `:` 始まりで,相対パスはエラー.相対パターンは `:workspace_roots` の下の入れ子の表なら許される(`.`・`..`
を含まない子孫パス).

## 判断・注意点

- 計画の決定どおり `"none"` を出力した.alias が外れると設定の読み込みが失敗する(黙って緩むことはない).その場合は
`"deny"` に切り替える.
- Linux などの非 macOS では,`**` の deny グロブは `glob_scan_max_depth`(既存の
5)までしか展開されない.それより深い秘密ファイルは設定では止まらず,フックの検査に頼る.
- 相対パターンは `:workspace_roots` の起点(プロジェクトルート)からの一致になる.

## テスト

- 競合の各形が,両方のエントリを示してエラーになる:同じパス,祖先,グロブ,`:workspace_roots`
の入れ子,生成側どうし(保護パスと読み取り禁止ルール).
- 書き込みのみのルールは Codex のエントリを生まない(ルールの有無で出力が同じ).読み取り禁止のルールは `"none"` になる.
- 重ならない組と,同じアクセスの重なりは通る.
- レビューで出た,ソースの `:root = "deny"` の下の例外は,書き換えではなくエラーになる.
- `guarded_path` の単体テスト:型の不変条件,正規化,祖先とグロブ,ルート間の独立,`:root`,波括弧,ドライブパス.
- golden:`tests/golden/complete_source/.codex/config.toml` に
`[permissions.guarded.filesystem.":workspace_roots"]` と `"**/secrets/**"
= "none"` が末尾に加わっただけ.他のプロバイダの生成物は変わらない.

## 検証

- `cargo test`:全件成功.ただし `tests/pi_provider.rs` の
`pi_bash_tool_runs_only_through_srt`(`pi_sandbox_smoke`)は,この環境では
`origin/main` でも失敗する.
- `cargo clippy -- -D warnings`,`cargo fmt --check`:成功
- 実際の
agent-config(`/Users/kaito/ghq/github.com/furedea/agent-config/agents`,読み取りのみ)で
`generate-codex-config-source` を実行:**成功**(競合なし,`"none"` が 26
件,書き込みのみのルールは出力に含まれない).

## フォローアップ(最終ラウンドの指摘.このPRでは直さない)

#235 で扱う.

-
`guarded_path.rs`(P2):間にある例外の判定は,緩いエントリと同じアクセスだけを受け入れる(`==`).より緩い間のエントリ(`:root
= "deny"` の下の `~ = "write"`)でも,生成された `read` は何も開かないのに「開く」というエラーになる.`<=`
にして,テストを足す.
- `guarded_path.rs`(P1):Windows のドライブ付きパスを大文字小文字を区別して比べている(`C:/Work` と
`C:/work`).ドライブとコンポーネントを正規化して比べる.
- `guarded_path.rs`(P2):バックスラッシュを Unix
でも区切りとして扱うため(直前の対応で入った),`/work/project\\name`
のようなファイル名の文字としてのバックスラッシュが区切りになり,兄弟パスが重なると誤判定する.Windows 形式のパスのときだけ区切りにする.

## 対象外(フォローアップ)

#235 で扱う.

- Pi のサンドボックスに秘密パスのポリシーが入っていない(`src/generation/pi_sandbox.rs`).
- `pi_sandbox_smoke`(`tests/pi_provider.rs` の
`pi_bash_tool_runs_only_through_srt`)が,この環境では `main` でも失敗する.
- `src/generation/assets/pi/bash_sandbox.ts` の jev-lint の指摘.

🤖 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