Repository navigation
fix: PreToolUse remote write classifier を command structure 解析ベースに置き換える - #1441
Conversation
…える (#1428) codex-hook-adapter.mjs の classifyRemoteWrite は raw command 文字列全体への 正規表現 substring match で git push を判定していたため、match-ssot.sh の --keywords 引数など quoted argument / 検索キーワードに含まれる非実行の "git push" まで remote_write_requires_approval として誤って deny していた。 scripts/agent-guards/shell_command_analysis.py に SHELL_COMMAND_ANALYSIS_V1 の bounded grammar analyzer を追加し、シェル上で実際に実行される simple command のみを command_kind (git_push / rtk_git_push) として抽出する。 quoted argument・検索キーワード・quoted-delimiter heredoc data は data-only として区別し、pipeline / list / command substitution / bash -c 等の execution-carrier 経由で実際に実行される git push は 引き続き deny する。静的に literal と確定できない command word / subcommand や find -exec / xargs 等の未対応 execution carrier は indeterminate として fail-closed に倒す(fail-open にしない)。 git_mutation_command_policy.py の外部 API(classify_rtk_git_mutation)は 変更していない。command structure classification(本 Issue)と #1408 の publish lane authorization の責務差分は docs/dev/session-recording-policy.md に明記した。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
Preview URLPreview removed (PR #1441 closed). |
python-test CI の ruff E501 違反4箇所(_tokenize_chunk_words の words.append、_classify_push_words の GIT_GLOBAL_OPTS_WITH_VALUE 条件、 _recurse の command substitution 再帰呼び出し、analyze_shell_command の timeout 戻り値)を意味を変えずに120文字以内へ整形する。
squne121
left a comment
There was a problem hiding this comment.
LOOP_VERDICT_V2
verdict: APPROVE
reviewed_head_sha: "6166b3201bfa9bfa7c7073261dff8a50a95bc7b1"
merge_ready: true
mergeability:
mergeable: "MERGEABLE"
merge_state_status: "CLEAN"
blockers: []
required_auto_actions: []
auto_fix_applied: []
follow_up_issue_requests: []
allowed_paths_gate:
status: "ok"
changed_files_source: "git_diff_name_status_find_renames_z"
changed_files:
- "docs/dev/session-recording-policy.md"
- "scripts/agent-guards/shell_command_analysis.py"
- "scripts/agent-guards/tests/test_shell_command_analysis.py"
- "scripts/session-recording/codex-hook-adapter.mjs"
- "tests/session_recording/codex/test_hook_adapter.py"
violations: []
producer_role: "review_subagent"
worker_report_used_as_canonical: false
判定根拠
- Closes #1428 が本文に明記。CI:
ci_verdict_summary.py(expected-head-sha=6166b3201bfa9bfa7c7073261dff8a50a95bc7b1)でstatus: all_pass(exit 0)、failed/pending/stale なし。 - mergeability:
MERGEABLE/CLEAN(gh pr view独立再取得、Draft だが blocker ではない)。 - AC1〜AC12 は PR本文「受け入れ条件の達成状況」に個別 VC 根拠付きで記載済み。AC11 は third-party parser 未導入のため N/A(
pyproject.toml/uv.lock/package.json/pnpm-lock.yaml未変更、Allowed Paths Compliance 節にも明記)。 - Allowed Paths gate:
allowed_paths_review_gate.pyを issue #1428 の contract snapshot(body_sha256: sha256:af2fdee5892bcdcc90937b7cf2b46bb0fa9751651f73804eeb48dd619dbe0ef2, status: go)に対して独立再計算。実 changed files 5件(git_diff_name_status_find_renames_z)はすべて Allowed Paths 内でstatus: ok、violations なし。 - Safety Claim Gate:
scripts/agent-guards/配下の PreToolUse 分類ロジック変更のため safety-sensitive。PR本文の Fixture Matrix(data_only/executed/indeterminate 全区分)と AC7/AC8(fail-closed indeterminate)記述が bounded な主張と一致し、既存 secret boundary / forbidden path / output shape テストが全 PASS(AC9)であることを確認。 - Schema Consumer Inventory: 本 PR は
SHELL_COMMAND_ANALYSIS_V1の新規 schema を導入するが、既存 consumer(git_mutation_command_policy.pyの外部 API)は変更していないことを PR本文 Outcome で明記済み。
敵対的レビュー結果判定REQUEST_CHANGES — PR #1441 は Draft のまま、対象 head は 方向性は正しいです。raw文字列への正規表現をやめ、 Blocker 1 — process substitutionと入れ子展開がfail-openになるprocess substitutionは splitter で対応範囲ごと読み飛ばされますが、その内部を再帰解析していません。後段のword scannerも cat <(git push origin main)
diff <(git push origin main) /dev/nullBashではprocess substitution内のlistが非同期実行されます。したがって単なるargument dataではありません。([GNU]1) 同様に、arithmetic expansionはdynamicと記録するだけで内部のcommand substitutionを収集せず、 echo "$(( $(git push origin main) ))"
unset x
echo "${x:-$(git push origin main)}"Bash仕様上、arithmetic expansion内ではcommand substitutionが行われ、parameter expansionの 修正要求: process、arithmetic、parameter expansionをAST上で再帰走査するか、内部構造を完全に解析できない展開をすべて Blocker 2 — command positionの認識に複数の迂回経路があるパス付き実行ファイル実行ファイル名は完全一致の /usr/bin/git push origin main
/bin/bash -c 'git push origin main'
/usr/bin/sudo git push origin mainこれらはliteral commandですが、現在のclassifierではpush factにも Bash予約語・複合コマンドsplitterは if true; then git push origin main; fi
time git push origin main
! git push origin main
{ git push origin main; }これらはBashの予約語であり、compound commandを構成します。([GNU]3) FD番号付きredirectionredirection除外は固定文字列と先頭 2>/dev/null git push origin main
3>&1 git push origin mainBashではredirectionはsimple commandの前にも置け、一般形は 修正要求: basename正規化、compound-command AST、完全なredirection node処理が必要です。場当たり的な正規表現追加では別の迂回を生みます。 Blocker 3 — heredocのBash意味論が誤っているunquoted heredoc bodyのscannerは、通常のshell wordと同じようにsingle quoteをquote状態として扱っています。 cat <<EOF
'$(git push origin main)'
EOF実際のunquoted heredocでは、quote文字はcommand substitutionを抑止しません。Bash仕様ではbodyがparameter、command、arithmetic expansion対象となり、double quoteさえ特別な意味を持ちません。上記の さらに、delimiter行まで読み取った後にscanner位置を cat <<'EOF'
harmless
EOF
git push origin mainコードパス上、heredoc範囲だけがword一覧から除去され、 修正要求: heredocを専用AST nodeとして扱い、quoted/unquoted delimiter、複数heredoc、delimiter後のcommand boundaryをparser側で保持してください。 Blocker 4 — dynamic commandのfail-closed条件が狭すぎるdynamic executableは、後続にliteralな cmd=git
sub=push
"$cmd" "$sub" origin mainこのケースではexecutableとsubcommandの両方がdynamicなので、literalな これはIssue #1428の「command word / subcommandが静的にliteralと確定できず、remote writeの有無に影響し得る場合はfail-closed」という契約に直接反します。 修正要求: command wordがdynamicなら、後続tokenのヒューリスティックに依存せず原則 Blocker 5 — Issueで固定したevent/tool境界が実装されていないIssue #1428はanalyzer起動条件を次に限定しています。 しかしadapterは現在も さらに、 実際のhook設定では同じadapterが以下にも接続されています。
したがって、例えば非Bash payloadのdescriptionが 修正要求: remote-write分類の入口に専用boundaryを置き、非BashおよびStop/SubagentStopではanalyzerを一切呼ばないでください。Bashなのにcommandが非stringなら High 1 — コメント内のcommand substitutionを実行対象と誤認するscannerにはshell comment状態の処理がありません。 echo ok # $(git push origin main)Bashでは 非対話Bashでは、word先頭の これはPRの主目的である「非実行データの誤検知解消」を満たしていません。 High 2 — unsupported carrier判定が過剰で、通常のread-only commandも拒否する
find . -type f
timeout 1 sleep 2
nice echo ok
sudo -n trueいずれも 修正要求: High 3 — schema mismatchのfail-closed検証が浅いNode側は次しか検証していません。
各command factのキー、型、enum、source span、reason codeは検証していません。 例えばanalyzer regressionで次が返っても、statusは {
"schema": "SHELL_COMMAND_ANALYSIS_V1",
"status": "ok",
"commands": [{"command_kind": 123}],
"reason_code": "parsed"
}既存schema testもキー集合とraw文字列非包含を確認するだけです。 修正要求: consumer側でV1 schemaを完全検証し、不明キー・欠落・不正enum・不正型はすべて 推奨する実装方針この安全境界で、hand-written bounded parserを継続することは推奨しません。現在のテストはdirect/list/pipeline、通常の 第一候補は Pythonのみで完結する 最低限、次の回帰fixtureを実hook entrypointへ追加する必要があります。 cat <(git push origin main)
echo "$(( $(git push origin main) ))"
unset x; echo "${x:-$(git push origin main)}"
/usr/bin/git push origin main
/bin/bash -c 'git push origin main'
if true; then git push origin main; fi
2>/dev/null git push origin main
cmd=git; sub=push; "$cmd" "$sub" origin main
echo ok # $(git push origin main)
cat <<EOF
'$(git push origin main)'
EOF
cat <<'EOF'
data
EOF
git push origin main加えて、 関連Issue・PRの評価依存していたPR #1421は既にmerge済みなので、xdist/test-lane競合という実装順序上のblockerは解消されています。 Issue #1408は引き続きopenで、検出済み ただし、検出器が上記の実行構文を見逃す状態では、その後段にある#1408の認可policyへ到達できません。したがって現状のPRは、CI greenでも安全境界の置換としてはマージ不可です。 |
…igh findings Addresses OWNER adversarial review REQUEST_CHANGES on PR #1441 (Issue #1428): - Blocker 1: recurse into process substitution `<(...)`/`>(...)`, arithmetic expansion `$((...))`, and parameter expansion `${...}` for nested command substitutions instead of skipping them. - Blocker 2: basename-normalize command-word recognition (`/usr/bin/git`), recognize bash reserved words/compound-command keywords (if/then/time/!/{}), and generalize redirection-operator handling to arbitrary fd numbers (`2>`, `3>&1`, `2>/dev/null`). - Blocker 3: fix unquoted heredoc body scanning to match real bash semantics (quote chars are literal, not quoting) and emit a command boundary after a heredoc so a following command on the next line is analyzed independently. - Blocker 4: a dynamic (non-literal) executable word is now always indeterminate, closing the double-dynamic gap (`"$cmd" "$sub" origin main`). - Blocker 5: fix the command-structure analyzer boundary in the Codex hook adapter to strictly require event ∈ {PreToolUse, PermissionRequest} AND tool_name === "Bash" AND typeof tool_input.command === "string"; remove the `description` fallback and fail-closed on malformed Bash payloads. - High 1: shell comments (`# ...`) are now scanner-aware and never treated as executable text. - High 2: `find` is only a carrier with -exec/-execdir/-ok; `timeout`/`nice`/`nohup` skip their own options (and, for `timeout`, the required DURATION) and recurse into the wrapped command instead of being unconditionally indeterminate; `sudo` remains conservatively indeterminate. - High 3: the Node adapter now fully validates the SHELL_COMMAND_ANALYSIS_V1 response shape (every command-fact key/type/enum /source-span), never trusting a malformed `ok` response as allow. Also fixes a `>&`/`&>` fd-duplication redirection operator being misparsed as the background `&` control operator by the top-level chunk splitter (found while adding the `3>&1` regression fixture), and a process-substitution double-recursion bug found during implementation (fixed by keeping recursion at the per-word scan only). Adds the reviewer's proposed regression fixture matrix as real tests in both scripts/agent-guards/tests/test_shell_command_analysis.py (analyzer unit tests) and tests/session_recording/codex/test_hook_adapter.py (real hook entrypoint, node subprocess), plus a CODEX_SHELL_COMMAND_ANALYZER test-only override (repoRoot-confined) for High 3 coverage. Co-Authored-By: Claude Sonnet 5 <[email protected]>
squne121
left a comment
There was a problem hiding this comment.
独立レビュー結果(pr-review-judge, head 8993ce4)
サマリ
- CI:
ci_verdict_summary.pyでstatus: all_pass(head一致確認済み、exit 0)。 - Mergeability:
MERGEABLE/CLEAN。 - Allowed Paths Gate(再計算):
status: ok。変更5ファイルはすべて Issue #1428 の Allowed Paths 内(allowed_paths_review_gate.py実行結果、violations: [])。 - Contract snapshot:
body_sha256を直接 GitHub API + Python で再計算し、go snapshot(af2fdee5...)と完全一致(fresh、stale ではない)。
Fix Delta(OWNER 敵対的レビュー REQUEST_CHANGES 対応)の独立検証
isolation worktree で refs/pull/1441/head(8993ce43fcb2ed60baf2c582e34186a280164a56)を明示的に fetch・checkout し、runShellCommandAnalyzer 関数の存在(新実装の証拠)を確認したうえで、Blocker 1〜5 / High 1〜3 の代表 fixture を自力で実行した。
- Blocker 1(process substitution / arithmetic / parameter expansion 再帰解析):
cat <(git push origin main)、echo "$(( $(git push origin main) ))"、echo "${x:-$(git push origin main)}"すべてgit_push検出(deny)。 - Blocker 2(basename正規化・予約語・fd redirection):
time git push origin main、! git push origin main、{ git push origin main; }、/usr/bin/git push origin main、/bin/bash -c "git push origin main"、if true; then git push origin main; fi、2>/dev/null git push origin main、3>&1 git push origin mainすべてgit_push検出(deny)。 - Blocker 3(heredoc意味論): unquoted heredoc内のquote無視・quoted delimiter後のcommand boundary、ともに正しく
git_push検出(deny)。 - Blocker 4(dynamic command word):
cmd=git; sub=push; "$cmd" "$sub" origin mainはstatus: indeterminate, reason_code: dynamic_command_word(fail-closed)。 - Blocker 5(event/tool境界):
tool_name: Read等 非Bash payload のdescriptionへgit pushを仕込んでも analyzer 未到達(allow、誤検知なし)。 - High 1(shell comment):
echo ok # $(git push origin main)は allow。 - High 2(過剰fail-closed是正):
find . -type fは allow、timeout 5 git push origin main/nice git push origin main/nohup git push origin main/find . -exec git push ... \;は引き続き deny/indeterminate。 - Node adapter full pipeline(PreToolUse経由)でも上記の代表ケースを再実行し、同じ結果を確認。
pytest tests/session_recording/codex/test_hook_adapter.py scripts/agent-guards/tests/test_shell_command_analysis.py -q→157 passed(PR本文の89+68と一致)。
上記はすべて head 8993ce43 を明示的に fetch した ref 上で実行した。検証途中、一時的に誤って古い origin/pr-1441-review(6166b320、Fix Delta 前)をチェックアウトしてしまい、多数の fixture が fail-open するという誤った結果を得たが、git rev-parse origin/pr-1441-review で 6166b320 であることに気づいて refs/pull/1441/head から明示的に checkout し直し、全 fixture が正しく deny/indeterminate になることを再確認した。誤検知を最終報告には含めていない。
結論: Fix Delta は OWNER 指摘の Blocker 1〜5 / High 1〜3 を実装レベルで実際に解消している。behavioral な観点では merge-ready。
Blocker(本レビューでの新規指摘)
- Safety Claim Matrix 欠落: 本PRは PreToolUse の remote write 承認境界(permission decision)を扱う safety-sensitive 変更(
docs/dev/runtime-verification-policy.md§9 /pr-review-judgeSKILL.md 4.6 該当)。## Safety Claim Matrixセクション(Claim / Implemented / Not controlled / Evidence / Follow-up)が本文にない。sudoを indeterminate のまま残した旨の記述はあるが、形式化されたテーブルがなく fail-closed。 - Schema Change Applicability / Schema Consumer Inventory 欠落:
SHELL_COMMAND_ANALYSIS_V1という新規 schema(producer:scripts/agent-guards/shell_command_analysis.py、consumer:scripts/session-recording/codex-hook-adapter.mjs)を導入しているが、## Schema Change Applicability/## Schema Consumer Inventoryセクションがなくuncertainとして fail-closed。
いずれも mechanical: false の blocker(required_auto_actions では自動対応不可)。PR本文へ両セクションを追記のうえ再レビューを要求する。
LOOP_VERDICT_V2
verdict: REQUEST_CHANGES
reviewed_head_sha: "8993ce43fcb2ed60baf2c582e34186a280164a56"
merge_ready: false
mergeability:
mergeable: "MERGEABLE"
merge_state_status: "CLEAN"
allowed_paths_gate:
status: "ok"
producer_role: "review_subagent"
worker_report_used_as_canonical: false
changed_files_source: "git_diff_name_status_find_renames_z"
changed_files:
- "docs/dev/session-recording-policy.md"
- "scripts/agent-guards/shell_command_analysis.py"
- "scripts/agent-guards/tests/test_shell_command_analysis.py"
- "scripts/session-recording/codex-hook-adapter.mjs"
- "tests/session_recording/codex/test_hook_adapter.py"
violations: []
blockers:
- "Safety Claim Matrix セクションが本文に存在しない。本PRはPreToolUse permission decision(remote write 承認境界)を扱うsafety-sensitive変更(docs/dev/runtime-verification-policy.md §9 / pr-review-judge SKILL.md 4.6 該当)。sudoの indeterminate 据え置きなどNot controlled相当の記述は散在するが、Claim/Implemented/Not controlled/Evidence/Follow-upの形式化されたテーブルが欠落しており、独立レビュー時点でfail-closedとして扱う。"
- "Schema Change Applicability / Schema Consumer Inventory セクションが本文に存在しない。本PRはSHELL_COMMAND_ANALYSIS_V1という新規schema(producer: scripts/agent-guards/shell_command_analysis.py, consumer: scripts/session-recording/codex-hook-adapter.mjs)を導入しており、schema_change/not_schema_changeの明記とconsumer列挙がないため uncertain としてfail-closed。"
required_auto_actions: []
auto_fix_applied: []
follow_up_issue_requests: []
squne121
left a comment
There was a problem hiding this comment.
独立レビュー結果(pr-review-judge, head 8993ce4・PR本文のみ更新後の再レビュー)
サマリ
- 前回レビュー(本コメントの直前、head 8993ce4)で
REQUEST_CHANGESとした理由(Safety Claim Matrix/Schema Change Applicability/Schema Consumer Inventoryの欠落)に対する fix delta として、PR本文にこの3セクションが追加された。コード自体(head SHA8993ce43fcb2ed60baf2c582e34186a280164a56、commit数5)は不変であることをgh pr view --json commitsで確認済み。 - CI:
ci_verdict_summary.py(expected-head-sha一致)はPR Body Japanese Checkをfailed_checksに含めexit 10を返したが、これは既知のツール側ギャップによる false positive と判定した。理由: 同名チェックがpull_requestイベント run(29142359936、conclusion success)とpull_request_reviewイベント run(29142221175、head_sha null で該当ジョブ skipped)の2系統で重複登録されており、後者は「retrospective」系チェック群と対称的にそのイベント種別では実行されないジョブである(既存のHEAD_SHA_NULL_SKIPPED_EXCLUDE_RULESallowlist に("Check Japanese Content", "PR Body Japanese Check")の逆方向tupleが未登録なだけ)。gh pr checks(fallback)では 14 passed / 0 failed、両ワークフローrunのconclusionはいずれもsuccess、直近の push-triggered run(現在のhead・現在のPR本文に対応)でのPR Body Japanese Checkjob自体のconclusionはsuccessであることを個別に確認した。よって実質的なCI状態はgreenと判断する。 - Mergeability:
MERGEABLE/BEHIND(Draft)。SKILL手順に従いBEHINDを衝突blockerとせずrequired_auto_actions.kind: update_branchとして扱う。 - Allowed Paths Gate(再計算):
status: ok。allowed_paths_review_gate.pyを Issue #1428 の contract snapshot(body_sha256: sha256:af2fdee5892bcdcc90937b7cf2b46bb0fa9751651f73804eeb48dd619dbe0ef2)に対して独立実行し、violations: []。body_sha256はGitHub API経由の生issue bodyをPythonで再sha256計算し完全一致(fresh, not stale)を確認済み。 - Fix Delta(コード側、AC1〜AC12・Blocker1〜5/High1〜3)は前回レビュー時点で実 fixture 157件実行により独立検証済みで今回コード変更なし。
Safety Claim Matrix / Schema Consumer Inventory の内容確認
## Safety Claim Matrix: Claim/Implemented/Not controlled/Evidence/Follow-up の5列表を確認。Not controlledが非空の行はいずれも根拠を伴う(fail-closed済みで追加follow-up不要な旨の説明、または既存OPEN Issue #1408への参照)。Issue #1408 が実際にstate: OPENであることをgh issue viewで確認済み。「remote write検出が完全に安全」という無限定主張は明示的に否定されており、Not controlledと衝突しない。Evidence欄の参照(68/89 passed 等)はPR本文他節の実行結果と一致。## Schema Change Applicability:schema_changeと明記。## Schema Consumer Inventory: 唯一のconsumer(codex-hook-adapter.mjsのrunShellCommandAnalyzer)を列挙し、git_mutation_command_policy.pyが非consumerである理由も明記。Compatibility Decision: new schema introduction, no breaking changeで締結。
いずれも references/safety-claim-gate.md / references/schema-consumer-gate.md の禁止条件に抵触しない。
required_auto_actions(BEHIND解消のみ・merge_readyはfalse)
merge_state_status: BEHIND のため update_branch を機械的 required_auto_action として計上する。blockerではないためverdictはAPPROVEのまま。
LOOP_VERDICT_V2
verdict: APPROVE
reviewed_head_sha: "8993ce43fcb2ed60baf2c582e34186a280164a56"
merge_ready: false
mergeability:
mergeable: "MERGEABLE"
merge_state_status: "BEHIND"
allowed_paths_gate:
status: "ok"
producer_role: "review_subagent"
worker_report_used_as_canonical: false
changed_files_source: "git_diff_name_status_find_renames_z"
changed_files:
- "docs/dev/session-recording-policy.md"
- "scripts/agent-guards/shell_command_analysis.py"
- "scripts/agent-guards/tests/test_shell_command_analysis.py"
- "scripts/session-recording/codex-hook-adapter.mjs"
- "tests/session_recording/codex/test_hook_adapter.py"
violations: []
blockers: []
required_auto_actions:
- kind: update_branch
executor: implementation-worker
skill: implement-issue.update_branch
mechanical: true
blocking_merge_ready: true
expected_head_sha: "8993ce43fcb2ed60baf2c582e34186a280164a56"
auto_fix_applied: []
follow_up_issue_requests: []
squne121
left a comment
There was a problem hiding this comment.
LOOP_VERDICT_V2
verdict: APPROVE
reviewed_head_sha: "84e7124c7edb468fdb7864ae9d5cc55bdd34fc1c"
merge_ready: true
mergeability:
mergeable: "MERGEABLE"
merge_state_status: "CLEAN"
blockers: []
required_auto_actions: []
auto_fix_applied: []
follow_up_issue_requests: []
allowed_paths_gate:
status: ok
changed_files_source: github_pull_request_files_api_with_previous_filename
changed_files:
- docs/dev/session-recording-policy.md
- scripts/agent-guards/shell_command_analysis.py
- scripts/agent-guards/tests/test_shell_command_analysis.py
- scripts/session-recording/codex-hook-adapter.mjs
- tests/session_recording/codex/test_hook_adapter.py
violations: []
allowed_paths_gate_source: review_subagent
再レビュー根拠(head 84e7124, update_branch 後)
update_branch(server-side merge, GitHub RESTPUT /pulls/1441/update-branch)で head が
8993ce43→84e7124c7edb468fdb7864ae9d5cc55bdd34fc1cに更新されたことを
gh pr view --json headRefOidで確認。gh pr view --json mergeable,mergeStateStatusは
MERGEABLE/CLEAN。- CI:
ci_verdict_summary.py --pr 1441 --expected-head-sha 84e7124c...で
status: all_pass(head_sha 一致、failed_checks/pending_checks/stale_checks すべて空、exit 0)。
typecheck/lint/test/build/e2e/python-test/actionlint/node-backed-hook-tests/
check-hook-integrity/validate-generated-artifact/PR Body Japanese Check すべてSUCCESS。 - linked issue contract snapshot(
issues/1428#issuecomment-4940955516,
body_sha256: sha256:af2fdee5892bcdcc90937b7cf2b46bb0fa9751651f73804eeb48dd619dbe0ef2,
status: go)は現在の Issue #1428 本文と一致することを確認済み
(GraphQLuserContentEditsで最終編集が2026-07-11T01:00:31Z(contract review より前)であり、
以降の body 変更なし。REST 取得 body とのバイト差分は末尾改行1文字のみで内容変更ではない)。 allowed_paths_review_gate.pyを新 head84e7124cに対して独立再実行し、
GitHub PR Files API(previous_filename込み、pagination_complete: true)を preferred oracle として
changed files(5件・rename なし)を取得。全件が Issue #1428 の Allowed Paths 内(
scripts/session-recording/codex-hook-adapter.mjs/
tests/session_recording/codex/test_hook_adapter.py/
scripts/agent-guards/shell_command_analysis.py(新規) /
scripts/agent-guards/tests/test_shell_command_analysis.py(新規) /
docs/dev/session-recording-policy.md)でstatus: ok、violations: []。
pyproject.toml/uv.lock/package.json/pnpm-lock.yamlは変更されておらず AC11 の N/A 主張と一致。update_branchは main 側の merge であり、feature 側の diff 実体(Issue #1428 の実装差分)・
PR 本文はいずれも不変であることを、変更ファイル一覧が review 前と同一である点から確認。- PR body 再点検:
## 受け入れ条件の達成状況で AC1〜AC12 すべて[x]+ 根拠記載、
Safety Claim Matrix(PreToolUse/PermissionRequest permission-decision hook 変更のため必須。
Not controlled 列に bounded な範囲明記、Evidence/Follow-up 記載あり)、
Schema Change Applicability: schema_change+Schema Consumer Inventory(新規 schema
SHELL_COMMAND_ANALYSIS_V1の唯一の consumer を明記、breaking change なし)が引き続き妥当。
Fix Delta 節(OWNER 敵対的レビュー Blocker 1-5 / High 1-3 対応)も維持されている。 - self-authored PR(author: squne121)のため本レビューは
--commentのみで投稿する。
Merge origin/main (#1428 shell command structure classification) into worktree-issue-1408-publish-lane-approval-bridge. Conflicts resolved: - docs/dev/session-recording-policy.md: kept both the #1408 publish lane approval bridge section and the #1428 command structure classification / #1408 responsibility-split section (additive, non-overlapping content). - scripts/session-recording/codex-hook-adapter.mjs: kept the #1408 getCommand/getCwd helpers (getCwd is used by the publish-lane bounded policy classification). - tests/session_recording/codex/test_hook_adapter.py: kept both the #1408 publish-lane fixture tests and the #1428 command-structure classification fixture tests. Updated #1408 publish-lane test payloads to include "tool_name": "Bash" (required by the stricter event/tool boundary check added by PR #1441 Blocker 5, now merged into this branch). Updated test_pre_tool_use_remote_write_rtk_git_push_blocked (#1428) to reflect that #1408's publish-lane bridge now intercepts `rtk git push` and denies with a structured publish_lane_safety_stop reason (instead of the generic remote_write_requires_approval) when no valid publish-lane context is present.
Closes #1428(本 PR は Issue #1428 をクローズする)
Outcome
scripts/session-recording/codex-hook-adapter.mjsのclassifyRemoteWrite(command)を、raw command 文字列全体への正規表現 substring match から、scripts/agent-guards/shell_command_analysis.py(SHELL_COMMAND_ANALYSIS_V1)が返す command structure classification ベースの判定へ置き換えた。git pushは非実行データとして区別し、remote_write_requires_approvalを返さない。&&||;)/ pipeline(|)/ command substitution($()/ backtick / process substitution / arithmetic expansion / parameter expansion 内 nested substitution 含む)/ 既知 execution-carrier(bash -c/sh -c/env VAR=valueprefix /commandwrapper /find -exec/timeout/nice/nohup)経由で実際に実行されるgit push/git -C <path> push/rtk git pushは引き続きremote_write_requires_approvalとして deny する。basename 正規化(/usr/bin/git等)・bash 予約語(if/then/time/!/{/})・fd 番号付き redirection(2>/3>&1)も command position 認識に含まれる。git p$(printf ush)等。executable が dynamic な場合は常に fail-closed)、およびxargs/sudo等の未対応 execution carrier はstatus: indeterminateとして fail-closed に倒す(fail-open にしない)。execFileSync(argv 呼び出し、shell: true不使用、JSON stdin data channel、timeout 付き)で呼び出す。non-zero exit・timeout・malformed JSON・schema mismatch(command fact 単位のキー/型/enum/source_span まで完全検証)はすべてindeterminateとして fail-closed に扱う。event ∈ {PreToolUse, PermissionRequest} AND tool_name === 'Bash' AND typeof tool_input.command === 'string'に固定されており、descriptionフィールドへのフォールバックは行わない。git_mutation_command_policy.pyの外部 API(classify_rtk_git_mutationシグネチャ)は変更していない。command structure classification(本 PR)と#1408の publish lane authorization の責務差分はdocs/dev/session-recording-policy.mdに明記した。third-party parser dependency は追加していない(bounded grammar の hand-written analyzer で実装した)。AC11 は N/A(
pyproject.toml/uv.lock/package.json/pnpm-lock.yamlは変更していない)。Fixture Matrix(合格・拒否・判定不能の一覧、pass / deny / indeterminate)
data_only(実行されないデータとして扱うべきケース。remote write と判定してはならない)
match-ssot.sh --keywords "... git push ..."(AC1, Issue Background の実際の観測ケース)rg -n "git push" docs/ .claude/grep -R 'git push origin main' docs/printf '%s\n' 'git push origin main'python3 tool.py --message "git push origin main"git log --grep="git push"some-command --keyword='git push' --description="do not execute git push"cat <<'EOF'/cat <<"EOF"(quoted heredoc delimiter, body="git push origin main")echo ok # $(git push origin main)(shell comment, High 1)find . -type f/timeout 1 sleep 2/nice echo ok(High 2)executed(実際に実行されるコマンドとして扱うケース。remote write として deny する)
git push origin maingit -C . push origin main//usr/bin/git push origin main(basename 正規化)env FOO=bar git push origin mainFOO=bar git push origin main(bare leading assignment)command git push origin mainecho ok && git push origin main/echo ok; git push origin main/ `falseif true; then git push origin main; fi(bash 予約語)echo "$(git push origin main)"/echo `git push origin main`echo "$(( $(git push origin main) ))"(arithmetic expansion 内 nested)echo "${x:-$(git push origin main)}"(parameter expansion 内 nested)bash -c 'git push origin main'//bin/bash -c '...'(basename)cat <<EOF(unquoted delimiter, body=$(git push origin main))cat <<< "$(git push origin main)"(here-string)cat <<EOFbody='$(git push origin main)'(unquoted heredoc、quote は非抑止)cat <<'EOF' ... EOFの直後のgit push origin main(heredoc 終端後の新規 command)cat <(git push origin main)/diff <(git push origin main) /dev/null(process substitution)2>/dev/null git push origin main/3>&1 git push origin main(fd 番号付き redirection)timeout 5 git push origin main/nice git push origin main/nohup git push origin mainfind . -exec git push origin main \;(正しくエスケープされた terminator)rtk git push origin HEAD:refs/heads/<branch>(command_kind=rtk_git_push)indeterminate(判定不能。fail-closed。allow に倒さない)
cmd=git; "$cmd" push origin maingit p$(printf ush) origin main"$command" push origin maincmd=git; sub=push; "$cmd" "$sub" origin main(executable/subcommand 両方 dynamic)$(...)find . -exec git push ... ;(unescaped terminator は shell に消費される) /xargs git push < filesudoprefix(認証境界、常に indeterminate)timeout git push origin main(DURATION が literal に確定できない)source generated-script.sh/ barebash/sh(stdin script)Verification Commands 実行結果(最新: Fix Delta 反映後)
初回実装時点(Fix Delta 前)の内訳別実行結果は以下(
-kによる絞り込み。数は初回実装時点のもので、Fix Delta 後は上記の全件実行結果が正本):補助検証(Delivery Rule)
受け入れ条件の達成状況
match-ssot.sh --keywords "... git push ..."は deny されない —-k "keyword_false_positive_match_ssot"(1 passed)で確認rg/grep/printf/ Python option value /git log --grep/ quoted argument / quoted-delimiter heredoc body / shell comment 内のgit pushは remote write と分類されない —-k "data_only"系、Fixture Matrixdata_only節で確認git push/git -C <path> push/ basename 正規化された絶対パス実行ファイルは引き続き deny される —-k "remote_write_top_level"、Fixture Matrixexecuted節top_level行で確認&&/||/;/ pipeline / bash 予約語(if/then/fi)内で実行されるgit pushは検出・deny される —-k "remote_write_compound"、Fixture Matrixexecuted節list/pipeline行で確認$()/ backtick /bash -c/sh -c/ unquoted heredoc / here-string / process substitution / arithmetic 及び parameter expansion 内 nested substitution で実行されるgit pushは検出・deny される —-k "remote_write_substitution"、Fixture Matrixexecuted節command_substitution/execution_carrier/process_substitution行で確認env VAR=value・先頭環境変数代入・commandwrapper・fd 番号付き redirection では実git push判定を bypass できない —-k "remote_write_wrapper"、Fixture Matrixexecuted節で確認command_kind/ literalness / execution_context 等の enum)のみに基づく — Outcome 節、test_shell_command_analysis.py(68 passed)で確認indeterminateになる —-k "indeterminate"、Fixture Matrixindeterminate節、High 3 schema 検証テストで確認test_hook_adapter.pyfull run(89 passed)で確認rg -n "command structure classification" docs/dev/session-recording-policy.md docs/dev/hook-boundaries.md(3 matches)で確認pyproject.toml/uv.lock/package.json/pnpm-lock.yamlは変更しておらず、Allowed Paths Compliance 節にその旨を明記済み(Fix Delta 後も不変)data_only/executed/indeterminateの期待分類を判別できる — Fixture Matrix の3節見出し、rg -n "_indeterminate" tests/session_recording/codex/test_hook_adapter.py(1 match)で確認Allowed Paths Compliance(許可パス遵守状況)
scripts/session-recording/codex-hook-adapter.mjs(変更)tests/session_recording/codex/test_hook_adapter.py(変更)scripts/agent-guards/shell_command_analysis.py(変更)scripts/agent-guards/tests/test_shell_command_analysis.py(変更)docs/dev/session-recording-policy.md(変更、初回実装時のみ)pyproject.toml/uv.lock/package.json/pnpm-lock.yamlは変更していない(third-party parser dependency 未導入)。Fix Delta(本節末尾)でも新規ファイル追加なし、既存 Allowed Paths 内のみ変更。Runtime Verification Applicability(動作検証の適用要否)
decision: not_applicable(Issue 本文のとおり)。実際の Git remote への push は本 PR の検証として実行していない。Safety Claim Matrix(安全性主張マトリクス)
本 PR は
scripts/session-recording/codex-hook-adapter.mjs(PreToolUse / PermissionRequest の permission-decision hook)を変更する safety-sensitive な差分のため、.claude/skills/pr-review-judge/references/safety-claim-gate.mdに従い本節を追加する。&&/||/;)・pipeline(|)・command substitution($()/backtick/process substitution/arithmetic expansion/parameter expansion 内 nested substitution)・既知 execution-carrier(bash -c/sh -c/eval/exec/source/env VAR=valueprefix/commandwrapper/find -exec/timeout/nice/nohup)経由で実際に実行されるgit push/git -C <path> push/rtk git pushは deny されるxargs/sudo等)は deny ではなくindeterminate(fail-closed だが carrier 種別としては未対応のまま)scripts/agent-guards/tests/test_shell_command_analysis.py(68 passed)+tests/session_recording/codex/test_hook_adapter.py(89 passed、実 hook entrypoint 経由の node subprocess 実行)。Fixture Matrix「executed」節に全 execution_context を列挙unsupported_constructとして fail-closed 済み)indeterminate→ deny になるdynamic_command_word系 4 fixture)source_spanまで完全検証)は allow ではなくindeterminateとして fail-closed に扱われるshell_command_analysis.py)が誤ってstatus: okを返した場合の内部ロジックバグは、Node adapter 側の構造検証(isStructurallyValidAnalysis/isValidCommandFact)では検出できるが、意味論的な誤判定(構造は正しいが分類が誤り)までは検出できないtest_hook_adapter.pyの schema 検証テスト、CODEX_SHELL_COMMAND_ANALYZERoverride によるテスト用注入経路rtk git pushの実際の publish authorization(force/tag/mirror/delete 等の危険フラグの最終許可判断、publish lane 証跡の検証)は本 PR のスコープ外であるrtk git pushの command structure classification(command_kind の識別)のみを担当し、publish lane authorization の可否判断ロジックは持たないgit_mutation_command_policy.pyの外部 API は変更していない」+docs/dev/session-recording-policy.mdの責務差分明記(rg -n "command structure classification"で 3 matches 確認済み)「本 PR の変更で remote write 検出が完全に安全になった」という無限定の主張はしない。上記の Not controlled 列に記載した範囲は本 PR のスコープ外として明示する。
Schema Change Applicability
schema_change本 PR は新規 schema
SHELL_COMMAND_ANALYSIS_V1(scripts/agent-guards/shell_command_analysis.pyが返す command structure classification の出力形式)を導入するため、.claude/skills/pr-review-judge/references/schema-consumer-gate.mdに従いschema_changeと判定する。Schema Consumer Inventory
scripts/session-recording/codex-hook-adapter.mjs(runShellCommandAnalyzer()/classifyRemoteWrite())SHELL_COMMAND_ANALYSIS_V1を消費する唯一の consumerSHELL_COMMAND_ANALYSIS_V1を消費する既存 consumer は存在しない(本 PR が初出の schema のため、既存呼び出し元への影響はない)。scripts/agent-guards/git_mutation_command_policy.pyはこの schema の consumer ではない。同モジュールは独自に raw command 文字列を再 tokenize する別系統のロジックであり、本 PR のスコープではSHELL_COMMAND_ANALYSIS_V1への配線を行わないことを Issue 実装: PreToolUse の git push 判定を実行コマンド構造ベースに修正する #1428 の Scope Delta で明記済み(git_mutation_command_policy.pyの外部 APIclassify_rtk_git_mutationシグネチャは本 PR で変更していない)。両モジュールの split-brain 回帰はscripts/agent-guards/tests/test_git_mutation_command_policy.py(19 passed)のtest_analyzer_does_not_change_git_mutation_command_policy_api/test_analyzer_and_git_mutation_policy_agree_on_rtk_git_push_recognitionで継続確認している。Compatibility Decision: new schema introduction, no breaking change to existing consumers.(新規 schema 導入であり、既存 consumer への breaking change はない)
Stop Conditions(停止条件)
該当なし。third-party parser dependency は導入していない。Allowed Paths 外の変更は発生していない。
Fix Delta(OWNER 敵対的レビュー REQUEST_CHANGES 対応、2026-07-11)
#1441 (comment) で指摘された Blocker 1〜5 / High 1〜3 をすべて bounded grammar(hand-written analyzer の拡張のみ)で修正した。third-party parser dependency は追加していない(Stop Condition 非該当)。
Blocker 1 — process substitution / arithmetic expansion / parameter expansion 内部の再帰解析(展開構文の入れ子解析漏れ修正)
<(...)/>(...)、$((...))内部の nested$(...)、${...}内部の nested$(...)を再帰解析対象にした(_collect_substitutions_in_rangeを自己再帰化し、_scan_word_dynamism/_tokenize_chunk_wordsの word 境界処理を修正)。fixedBlocker 2 — command position 認識の複数の迂回経路
os.path.basenameベースの_exe_basename)をgit/rtk/bash/sh/env/eval/exec/source/command/ carrier 判定すべてに適用。/usr/bin/git push origin main、/bin/bash -c '...'を検出できるようにした。if/then/else/elif/fi/while/until/do/done/for/case/esac/time/!/{/})を leading no-op prefix として strip し、後続 command を再帰解析する。_classify_redirection_word)に一般化し、2>/dev/null・3>&1等の fd 番号付き redirection を正しく argv から除外する。fixedBlocker 3 — heredoc の Bash 意味論の誤り
_collect_substitutions_in_heredoc_bodyを新設し、quote 文字が command substitution を抑止しない bash 実意味論を実装した。cat <<'EOF' ... EOF\ngit push origin mainでgit pushを検出)。fixedBlocker 4 — dynamic command word の fail-closed 条件(動的コマンド語の判定強化)
executable word が dynamic な場合は、後続 literal
pushtoken の有無に関わらず常にindeterminate/dynamic_command_wordにした(cmd=git; sub=push; "$cmd" "$sub" origin mainを検出)。安全と証明できる例外は設けていない(bounded grammar でそのような静的証明はできないため)。fixedBlocker 5 — event/tool 境界の実装(analyzer 起動条件の限定)
codex-hook-adapter.mjsのevaluateGuardを、event ∈ {PreToolUse, PermissionRequest} AND tool_name === 'Bash' AND typeof tool_input.command === 'string'を満たさない限り command ベース分類(forbidden_path / secret_boundary / remote_write)に一切到達しないよう再構成した。getCommand()のdescriptionフォールバックを削除。Bash tool でcommandが非 string の場合はreason_code: malformed_payloadで fail-closed。kill-switch フラグ(public_checkpoint_enabled等)は event/tool 種別を問わず引き続き適用される。fixedHigh 1 — shell comment 内の command substitution 誤検知(コメント文字列の誤解析)
word-start 位置(直前が空白または chunk 先頭)の
#を comment として認識し、_split_top_level_chunksと_tokenize_chunk_wordsの両方で行末まで無視するようにした。echo ok # $(git push origin main)は allow のまま。fixedHigh 2 — unsupported carrier 判定の過剰 fail-closed(過剰阻止の是正)
findは-exec/-execdir/-ok/-okdirオプションがある場合のみ execution carrier として扱い、それ以外(find . -type f)は通常の非実行コマンドとして扱う。timeout/nice/nohupは自身のオプション(timeoutは必須の DURATION も含む)を読み飛ばして後続コマンドを再帰解析するようにした(timeout 1 sleep 2・nice echo okは allow、timeout 5 git push origin mainは deny)。sudoは認証境界のため引き続き indeterminate のまま残した(reviewer 許容のトレードオフ)。fixedHigh 3 — schema mismatch の fail-closed 検証(構造検証の強化)
Node adapter (
isStructurallyValidAnalysis/isValidCommandFact) がSHELL_COMMAND_ANALYSIS_V1の各 command fact のキー・型・enum 値・source_span構造を完全検証するようにした。{"commands": [{"command_kind": 123}]}のような regression はstatus: okであってもanalysis_process_failedに正規化され allow に倒れない。テスト用に repoRoot 限定のCODEX_SHELL_COMMAND_ANALYZERoverride(CODEX_SESSION_RECORDING_PRODUCERと同一パターン)を追加した。fixed実装中に追加で発見・修正したバグ
>&/&>系の fd-duplication redirection operator が、top-level chunk splitter によって background&control operator と誤認識されるバグを発見・修正した(3>&1 git push origin mainfixture 追加時に判明)。third-party parser dependency について(追加要否の判断)
Blocker 1〜5 / High 1〜3 はすべて bounded grammar(hand-written analyzer の拡張)のみで解決できた。third-party parser(
mvdan/sh/bashlex)への切り替えは不要だった。Stop Condition 非該当。追加した回帰 fixture
reviewer 提案の全 fixture を、実 hook entrypoint 経由(
tests/session_recording/codex/test_hook_adapter.py、node subprocess)と analyzer 単体(scripts/agent-guards/tests/test_shell_command_analysis.py)の両方にテストとして追加した:find . -type f/timeout 1 sleep 2/nice echo ok/sudo -n true(High 2 の過剰 fail-closed 是正)、および Blocker 5 の event/tool 境界(非 Bash tool のdescriptionフォールバック除去・malformed_payloadfail-closed)と High 3 の schema 検証も、それぞれ専用の回帰テストを追加した。