Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#1154"
goal_ref: "agent-skill-runtime-hook-relaxation"
change_kind: workflowParent Issue
Parent Goal Ref
- Goal: AI agent の skill 実行経路を、security hook を無効化せずに通せるようにする。
- Desired Destination: mutation-capable な
publish_termination_report.pyを root checkout から扱う必要が出ても、preflight.run用 privileged executor と混線させず、別の controlled mutation policy と exact command class で安全に扱える状態。
Current Validated Scope
publish_termination_report.pyを root allow 対象にする必要性と境界を、preflight.run用 policy から分離して定義するtermination_report.publishcommand ID としてCONTROLLED_SKILL_MUTATION_COMMAND_POLICYに分離設計するcontrolled_skill_mutation_exec.pyによる単一 executor が repo binding・--repo必須・--input-fileartifact subtree 制限・env sanitization・idempotency read-back を担うworktree_scope_guard.py/local_main_branch_guard.py/ settings / docs / tests の最小同期に閉じる
Remaining Parent Gaps
preflight.run以外の非 mutating runtime command の root allow 拡張- producer output budget / schema mismatch / termination bypass の fail-closed 強化
- registry の追加 command ID を privileged set に広げる設計
Outcome
publish_termination_report.py を root checkout から扱う必要がある場合でも、termination_report.publish という controlled remote mutation transaction として、repo/issue/input/artifact/env/import/postcondition/idempotency に束縛した単一 executor 経由でのみ許可できる状態。直接 script allow は deny される。
In Scope
termination_report.publishcommand ID を持つ独立 mutation policy の設計(CONTROLLED_SKILL_MUTATION_COMMAND_POLICY)controlled_skill_mutation_exec.pyによる単一 executor 実装(direct script allow を deny)- repo/issue binding・
--repo明示・--input-fileartifact subtree 制限 PUBLISH_ARTIFACT_DIR/PYTHONPATH/PYTHONHOME/ editor 系 env を executor で sanitize- module realpath 検査(publisher / renderer / prose_boundary_policy の canonical path 固定)
- idempotency marker の pre-post チェックと read-back(comment id/url/body hash)
- 実 hook 経路テストと negative fixture(deny/allow 両軸)
worktree_scope_guard.pyとlocal_main_branch_guard.pyの shared policy function による統合publish_termination_report.pyへの--repo必須化・--input-file制限・artifact dir 固定の最小変更- guardrail 境界の明記(docs 更新)
- 必要最小限の settings / docs 更新
Out of Scope
preflight.run用 privileged executor の実装- producer output budget / schema mismatch / termination bypass テストの修正(実装: issue-refinement-loop producer の fail-closed routing を固定する #1165 の責務)
- registry 全件自動許可
.claude/skills/**/*.pyの blanket allow- 実装: issue-refinement-loop producer の fail-closed routing を固定する #1165 producer fail-closed routing の修正を同一 PR に含めること
Acceptance Criteria
- AC1:
CONTROLLED_SKILL_MUTATION_COMMAND_POLICYがscripts/agent-guards/controlled_skill_mutation_policy.pyに定義され、preflight.run用 policy とは別ファイルで分離される - AC2: exact command class は
controlled_skill_mutation_exec.pyへの executor argv のみを受け付け、python3 .claude/skills/.../publish_termination_report.py・prefix match・shell chain・inline env・bash -lc・python -c・/tmpscript を deny する - AC3: policy は
termination_report.publishcommand ID ごとに allowed_write_roots・GitHub mutation 条件・postcondition を明示する - AC4:
worktree_scope_guard.pyとlocal_main_branch_guard.pyが同一の shared policy function を consume し、独自 allowlist を split-brain させない - AC5: 実 PreToolUse hook 経路テストが deny/allow 両軸の negative/positive fixture を実 hook stdin JSON で確認する
- AC6:
.claude/settings.json・docs・tests の eligible command 集合が mutation policy と一致し、wildcard allow を追加しない - AC7: 標準ゲートが PASS する
- AC8: command ID は
termination_report.publishのみ。preflight.runpolicy / registry mutation flag /gh.issue.commentregistry entry を認可根拠にしない - AC9: executor command のみを exact allow し、
python3 .claude/skills/.../publish_termination_report.pyへの direct allow は deny する - AC10: repo は canonical origin repository に一致し、GitHub comment は explicit
--repo squne121/loop-protocolで投稿される。publisher 側の--repo必須化変更を Allowed Paths に含める - AC11:
--issue-number・input.issue_number・active issue・artifact subtree issue slot がすべて一致する - AC12:
--input-fileは active issue artifact subtree 内の既存 regular file のみ許可。absolute path・..・symlink・hardlink・stdin freeform を deny する - AC13:
PUBLISH_ARTIFACT_DIR/PYTHONPATH/PYTHONHOME/GH_EDITOR/EDITOR/VISUAL/BROWSERを executor が sanitized env で制御する - AC14: allowed_write_roots 外のファイル変更・tracked source / lockfile / settings 変更を postcondition で deny する
- AC15: publish success は comment id/url/body hash/idempotency marker を read-back し、重複 marker では二重投稿しない
- AC16: renderer / publisher / prose_boundary_policy の canonical realpath と import origin を検査し、module shadowing を deny する
- AC17:
worktree_scope_guardとlocal_main_branch_guardは shared policy function を consume し、独自 allowlist の split-brain を作らない(AC4 と連携) - AC18:
#1165の producer fail-closed routing とは責務を分ける。#1166は upstream artifact provenance を要求するが、producer の schema mismatch 修正を同一 PR に含めない
Verification Commands
# baseline-expect: fail
# AC1
# preflight-scope: pr_review_only
$ rg -n "CONTROLLED_SKILL_MUTATION_COMMAND_POLICY" scripts/agent-guards/controlled_skill_mutation_policy.py
# baseline-expect: fail
# AC2
$ rg -n "publish_termination_report.py" .claude/hooks/tests/test_worktree_scope_guard.py
# baseline-expect: fail
# AC3
$ rg -n -e "allowed_write_roots" -e "postcondition" docs/dev/agent-skill-boundaries.md
# baseline-expect: fail
# AC4
$ rg -n "publish_termination_report" scripts/agent-guards/local_main_branch_guard.py
# baseline-expect: fail
# AC5
$ rg -n "def test_publish_termination" .claude/hooks/tests/test_worktree_scope_guard.py
# baseline-expect: fail
# AC6
$ rg -n "publish_termination_report.py" .claude/settings.json
# AC7
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm build
# baseline-expect: fail
# AC8
# preflight-scope: pr_review_only
$ rg -n "termination_report.publish" scripts/agent-guards/controlled_skill_mutation_policy.py
# baseline-expect: fail
# AC9
$ rg -n "controlled_skill_mutation_exec.py" .claude/settings.json
# baseline-expect: fail
# AC10
$ rg -n "\-\-repo" .claude/skills/issue-refinement-loop/scripts/publish_termination_report.py
# baseline-expect: fail
# AC11
# preflight-scope: pr_review_only
$ rg -n "issue_number.*active" scripts/agent-guards/controlled_skill_mutation_exec.py
# baseline-expect: fail
# AC12
# preflight-scope: pr_review_only
$ rg -n "input.file.*artifact" scripts/agent-guards/controlled_skill_mutation_exec.py
# baseline-expect: fail
# AC13
# preflight-scope: pr_review_only
$ rg -n -e "PUBLISH_ARTIFACT_DIR.*sanitize" -e "sanitize.*env" scripts/agent-guards/controlled_skill_mutation_exec.py
# baseline-expect: fail
# AC14
# preflight-scope: pr_review_only
$ rg -n -e "allowed_write_roots.*postcondition" -e "postcondition.*allowed_write_roots" scripts/agent-guards/controlled_skill_mutation_policy.py
# baseline-expect: fail
# AC15
# preflight-scope: pr_review_only
$ rg -n -e "idempotency_marker" -e "read.back" scripts/agent-guards/controlled_skill_mutation_exec.py
# baseline-expect: fail
# AC16
# preflight-scope: pr_review_only
$ rg -n -e "realpath.*renderer" -e "renderer.*realpath" scripts/agent-guards/controlled_skill_mutation_exec.py
# baseline-expect: fail
# AC17
$ rg -n -e "shared_policy" -e "controlled_skill_mutation_policy" scripts/agent-guards/local_main_branch_guard.py
# baseline-expect: fail
# AC18
# preflight-scope: pr_review_only
$ rg -n "termination_report.publish" scripts/agent-guards/controlled_skill_mutation_policy.pyRuntime Verification Applicability
decision: not_applicable
理由: 本 Issue の verification は実 PreToolUse hook stdin JSON を用いた pytest ハーネステスト(AC5)により CI 内で完結する。production 実行なしに deny/allow 両軸を決定論的に確認できるため、runtime-verification: true は不要。
Allowed Paths
.claude/settings.json.claude/hooks/worktree_scope_guard.py.claude/hooks/worktree_scope_guard.sh.claude/hooks/tests/test_worktree_scope_guard.py.claude/hooks/tests/test_local_main_branch_guard.pyscripts/agent-guards/local_main_branch_guard.pyscripts/agent-guards/controlled_skill_mutation_policy.pyscripts/agent-guards/controlled_skill_mutation_exec.pyscripts/agent-guards/tests/__init__.pyscripts/agent-guards/tests/test_controlled_skill_mutation_policy.pyscripts/agent-guards/tests/test_controlled_skill_mutation_exec.py.claude/skills/issue-refinement-loop/scripts/publish_termination_report.py.claude/skills/issue-refinement-loop/tests/test_publish_termination_report.pydocs/dev/agent-skill-boundaries.md
Scope Delta
実装時に Allowed Paths 外に有価テストが追加されたため、Scope Delta として拡張する。
追加ファイル:
scripts/agent-guards/tests/__init__.py: 新規 agent-guards/tests パッケージ初期化scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py: policy の deny/allow 単体テスト(56 tests)scripts/agent-guards/tests/test_controlled_skill_mutation_exec.py: executor の deny/allow 単体テスト(23 tests).claude/skills/issue-refinement-loop/tests/test_publish_termination_report.py: publisher の --repo 必須化テスト(45 tests)
理由: AC5 の実 hook stdin JSON テストを補完する unit coverage であり、実装品質向上に必須。削除より Scope Delta 拡張が適切(feedback_test_outside_allowed_paths.md 準拠)。
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
preflight.run用 policy と同一 executor に統合しないと成立しないと判明した場合#1165の producer fail-closed 修正が前提になると判明した場合
Required Skills
- Python 3
- pytest
Scope Delta(任意)
上記「## Scope Delta」セクション参照。
Delivery Rule
1 Issue = 1 PR。worktree: worktree-issue-{N}-publish-termination-controlled-mutation。Draft PR で起票。
Activity
squne121 commentedon Jun 26, 2026
判定
REQUEST_CHANGES。#1166 の分離方針は妥当ですが、現行 Issue contract のまま実装すると root checkout からの GitHub mutation を過小評価します。
#1166 は
publish_termination_report.pyをpreflight.run用 privileged executor とは別の controlled mutation policy / exact command class で扱うことを目的にしており、コメントは現時点で空です。 ただし、本文の AC は「allowed write roots / GitHub mutation 条件 / postcondition を書く」ところで止まっており、現行publish_termination_report.pyが持つ repo/issue binding、入力 provenance、環境変数、artifact 書込み、GitHub CLI 呼び出し の実リスクをまだ閉じていません。親 #1154 は、
mutation:falseや registry metadata を認可根拠にせず、preflight.run専用の deny-by-default policy と単一 executor に閉じる設計へ絞っています。 そのレビューコメントでも、mutation:falseは認可属性として使えず、uv.pytestやpnpm.*のような repo-root 実行 command も project-controlled code execution になるため、明示的な privileged subset と effect/path binding が必要だと指摘されています。 #1166 はこの判断の延長線上にありますが、対象が read-only preflight ではなく GitHub issue comment publisher なので、#1154 より厳しい contract が必要です。P0-1:
publish_termination_report.pyは “script allow” ではなく “remote mutation transaction” として扱うべき現行 publisher は renderer を subprocess で呼び、その結果が
publishable=trueの場合にgh issue comment <issue> --body-file -を実行します。 これは単なる skill runtime command ではなく、GitHub issue comment を作成する remote mutation です。問題は、現在の
_post_github_comment()が--repoを渡していない点です。 GitHub CLI のgh issue commentは--body-file -による stdin body をサポートし、さらに inherited option として--repo <OWNER/REPO>を持ちます。--repoを明示しない実装は、cwd / gh context / env に repo 解決を委ねます。([GitHub CLI]1)必須修正: policy だけでなく publisher 実行境界で、少なくとも次を固定してください。
ここで重大なのは、#1166 の Allowed Paths に
.claude/skills/issue-refinement-loop/scripts/publish_termination_report.pyが含まれていないことです。 現行 publisher を安全にするには--repo必須化、--input-file制限、artifact dir 制御など script 側の変更が必要になる可能性が高いです。したがって、現 Issue は Allowed Paths を広げるか、executor 側で publisher を呼ばずに repo-bound posting transaction を実装するか を明記しない限り、Stop Condition に入る設計です。P0-2:
PUBLISH_ARTIFACT_DIRが allowed write roots を無効化するpublish_termination_report.pyはARTIFACT_DIR = Path(os.environ.get("PUBLISH_ARTIFACT_DIR", "artifacts"))としており、失敗・非 publish 時に artifact をそこへ書き込みます。 つまり root allow された command は、環境変数を通じて書込み先を任意に変更できる可能性があります。#1166 は allowed write roots を policy に書くとしていますが、現行実装では policy だけでは不足です。executor が
PUBLISH_ARTIFACT_DIRを完全に上書きするか、publisher 側で固定 path 以外を拒否する必要があります。推奨 contract:
Python の
subprocessはshell=Falseならシェルメタ文字を shell に解釈させませんが、cwd、env、実行ファイル解決はアプリケーション側の責務です。公式ドキュメントも args sequence と明示的 executable 解決を推奨しています。([Python documentation]2)P0-3:
--input-fileは任意ファイル read capability になっているCLI は
--input-fileを受け取り、指定された path をPath(args.input_file).read_text()で読み込みます。 root checkout から exact command class として許可する場合、--input-file /abs/path、../../...、symlink、artifact subtree 外ファイルを明示的に拒否しないと、publisher が任意の root-side file を読み、その内容を renderer 経由で GitHub comment に流す経路になります。現 renderer は入力 schema を検証しますが、
issue_numberが CLI の--issue-numberや active issue と一致することまでは検証していません。 したがってpublishable=trueの renderer result だけを信頼してはいけません。必須修正: root allow する exact command では、
--input-fileを自由指定にしないでください。許すなら capability type を以下に限定すべきです。検証条件:
P0-4:
publishable=trueは認可ではないpublish()は renderer output を validate し、publishable=trueかつ body が非空なら GitHub comment を投稿します。_validate_render_result()は schema/version、publishable型、body/reason_code invariant を見ます。 これは format validation であり、投稿してよいという authorization ではありません。#1165 は producer / publisher の schema mismatch、output budget violation、termination bypass を fail-closed に固定する sibling issue で、root allow policy は対象外としています。 したがって #1166 は #1165 の代替になってはいけません。逆に #1166 側では、#1165 が保証する fail-closed producer output を 前提 artifact として参照するだけに留めるべきです。
必須の追加条件:
P0-5: idempotency と read-back がないと comment spam / duplicate publish を防げない
現行 publisher は、
gh issue comment成功時に stderr へ “comment posted” と出すだけで、comment ID / URL / body hash / idempotency marker の read-back を契約化していません。 root allow された controlled mutation として扱うなら、成功後の postcondition はローカルファイル不変だけでは不十分です。必要な postcondition:
gh issue commentには--edit-last、--delete-last、--web、--editor、--create-if-noneなどの option が存在するため、executor/policy は publisher 内部・外部のどちらでも、comment create 以外の mutation mode を絶対に許可しない必要があります。([GitHub CLI]1)P0-6: import path / module shadowing が threat model に入っていない
publish_termination_report.pyは sibling のrender_termination_reportを通常 import しています。 さらに renderer は.claude/skills/create-issue/scriptsをsys.path.insert(0, ...)してprose_boundary_policyを import しています。これ自体は現行 skill 実装として理解できますが、root privileged execution の認可境界では不十分です。#1154 のレビューでも、通常 import による stale
/tmp/command_registry.py混入のような失敗を避け、canonical absolute path /spec.origin/__file__検査を求めています。必須修正: executor は少なくとも次を行うべきです。
P0-7: direct
publish_termination_report.pyallow は既存 guard 設計と衝突する現在の
worktree_scope_guard.pyは #1137 系の agent-ops script だけを exact allow し、script realpath、cwd、default branch、argv shape を検査しています。 これは #1143 で確立した「単一 executor / exact class / real hook path / claim-first」パターンです。#1166 で
publish_termination_report.pyを直接_AGENT_OPS_ALLOWED_SCRIPTSのような allowlist に追加するのは逆行です。対象は agent-ops read/cleanup 補助ではなく GitHub mutation publisher です。別 module で、例えば次のように分けるべきです。allow される Bash は publisher そのものではなく、以下のような executor だけにしてください。
Python の
shlexは shell-like syntax の字句解析であり、authorization boundary ではありません。shell 文字列の逆照合ではなく、executor がargvlist を生成してshell=Falseで実行する形に寄せるべきです。([Python documentation]3)P1: Claude / Codex hook は sandbox ではなく guardrail と明記すべき
Codex の hooks documentation は、PreToolUse が Bash / apply_patch / MCP tool calls を intercept できる一方、完全な enforcement boundary ではなく、別 tool path で同等作業ができる場合があると明記しています。([OpenAI デベロッパー]4) Claude Code 側も、hook matcher の
ifは best-effort で、hard allow/deny には permission system を使うべきだと説明しており、command hook は current directory と Claude Code environment を引き継ぎます。exec form ではargsがそのまま argv として渡され、shell tokenization が起きないため、path placeholder を扱う hook では exec form が推奨されています。([Claude Platform Docs]5)#1166 の docs には、次を明記してください。
修正版 Issue contract に追加すべき AC
現行 AC1〜AC7 に加えて、最低限これを入れるべきです。
negative fixture はこれだけでは足りない
#1166 の AC5 は “positive / negative” としか書いていません。過去 #1139 / #1143 では、関数直接呼び出しや改行 command injection、one-shot consume fail-open が blocker になっています。 今回の negative fixture は、少なくとも以下を実 hook stdin JSON で回すべきです。
最終結論
#1166 は 必要な分割 です。#1154 の
preflight.runprivileged executor と、#1165 の producer fail-closed routing からpublish_termination_report.pyの mutation policy を分離する方向は正しいです。ただし、現行 contract はまだ 「GitHub comment を作る transaction」ではなく「Python script を root から allow する話」 として書かれています。これは危険です。採用条件は次の一点に集約できます。
publish_termination_report.pyを直接 allow しない。termination_report.publishという controlled remote mutation transaction を、repo/issue/input/artifact/env/import/postcondition/idempotency に束縛した単一 executor 経由でだけ許可する。この形に Issue 本文と AC を書き直した後で着手するのが妥当です。
squne121 commentedon Jun 26, 2026
Refinement Loop: Human Escalation Required
The loop has terminated and requires human review. Cause: human judgment required
human_escalationhuman_judgment_requiredBlockers
squne121 commentedon Jun 26, 2026
Contract Review Result
fix(#1166): fix Ruff F401 unused imports + register agent-guards test…
squne121 commentedon Jun 26, 2026
IMPL_REVIEW_LOOP_RESULT_V1:
schema: IMPL_REVIEW_LOOP_RESULT_V1
verdict: APPROVE
merge_ready: true
pr_number: 1182
reviewed_head_sha: c266595
pr_url: #1182
verdict_comment_url: #1182 (comment)
issue_number: 1166
iteration: 0
reviewer: pr-review-judge-subagent
ci_gate:
result: PASS
run_id: 28245770230
conclusion: success
allowed_paths_gate:
result: PASS
files_outside_allowed_paths: 0
producer_role: review_subagent
worker_report_used_as_canonical: false
ac_summary:
total: 18
pass: 18
fail: 0
indeterminate: 0
blockers: []
next_action: human_merge
notes:
- 全 18 AC 充足。PR は APPROVE かつ merge_ready。
- 人間によるマージ待ち。
fix(#1166): OWNER REQUEST_CHANGES 対応 — P0-1〜P0-6 + P1-1〜P1-4 hardening
feat(#1166): hooks: controlled skill mutation policy for publish_term…
fix(#1166): fix Ruff F401 unused imports + register agent-guards test…
fix(#1166): OWNER REQUEST_CHANGES 対応 — P0-1〜P0-6 + P1-1〜P1-4 hardening
squne121 commentedon Jun 26, 2026
IMPL_REVIEW_LOOP_RESULT_V1
feat(#1166): hooks: controlled skill mutation policy for publish_term…
squne121 commentedon Jun 26, 2026
post-merge-cleanup: 完了 (2026-06-27T00:10Z)
pr_head_oid_mismatch)docs(agent-skill-boundaries): document issue-refinement-loop producer…
fix(issue-refinement-loop): add fail-closed routing to compact produc…
fix: python-test-plan.json に scripts/trust-root/tests/ を登録する (#1454)
feat: publish lane authorization の external trust root を確立する (#1457)