Skip to content

実装: agent の root temporary residue を hook と docs で防止する #1404

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#1395"
goal_ref: "Claude Code / Codex CLI が repo root に .tmp/ のような未追跡 temporary alias を残さないよう、非ブロッキング advisory hook と folder policy SSOT で誘導・分類する"
change_kind: workflow
preflight_scope: implementation
runtime_verification:
  required: true
  mode: immediate
  evidence_type: hook-advisory-and-folder-policy-tests

Parent Issue

#1395

Parent Goal Ref

  • PR fix: preflight repair hint と hook docs を整合させる (#1395) #1399 の post-merge-cleanup 後、repo root に未追跡 .tmp/ が残った。
  • agent が root temporary alias を作成して削除しないと、cleanup のたびに unrelated residue として残り続ける。
  • owner comment は .tmp/ 作成を block せず、tmp/ など repo-approved temporary area へ案内することを要求している。

Current Validated Scope

  • repo root の .tmp/ / .temp/ / .tmp-* など root temporary alias を検出し、Claude / Codex hook から non-blocking advisory を返す。
  • advisory は REPO_TEMP_FOLDER_ADVICE_V1 として hookSpecificOutput.additionalContext に載せ、exit code 0 で tool call を止めない。
  • tmp/ と、repo policy で明文化された .claude/tmp/ などの許可済み temporary area を folder policy SSOT に固定する。
  • cleanup / post-merge-cleanup は root temporary residue を自動削除しない report-only 境界として docs / skill に明記する。
  • ownership marker に基づく deterministic cleanup classifier は 実装: root temporary residue cleanup classifier を構造化する #1417 に分離し、この Issue では実装済み claim にしない。

Remaining Parent Gaps

Outcome

agent が repo root に .tmp/ や類似の未追跡 temporary directory を作成しようとした場合、Claude / Codex hooks は tool call を block せず、tmp/ または repo-approved temporary area を使うよう REPO_TEMP_FOLDER_ADVICE_V1 を model-visible context として返す。作業後に root temporary residue が残った場合、この Issue では post-merge-cleanup docs / skill が report-only 境界と approved temporary root の自動削除禁止を明記する。ownership marker に基づく deterministic cleanup classifier は #1417、schema catalog 登録は #1418 で扱う。

In Scope

  • root temporary alias (.tmp/, .temp/, .tmp-*) の advisory-only hook policy を追加する。
  • Claude / Codex の PreToolUse hook registration と parity tests を追加する。
  • REPO_TEMP_FOLDER_ADVICE_V1 schema と producer を追加する。
  • docs/dev/repository-folder-policy.md などの folder policy SSOT を追加し、approved / denied / report-only temporary roots を明記する。
  • post-merge-cleanup docs に root temporary residue の report-only 分類と自動削除禁止を明記する。
  • 許可済み temporary folder の破壊防止ルールを docs に固定し、実行可能な classifier は 実装: root temporary residue cleanup classifier を構造化する #1417 に残す。
  • .gitignore に .claude/tmp/ を repo-approved local temporary workspace として明示する。

Out of Scope

Acceptance Criteria

  • AC1: mkdir .tmp / mkdir -p .tmp/foo / mkdir .temp は Claude / Codex PreToolUse hook で block されず、exit code 0 で REPO_TEMP_FOLDER_ADVICE_V1 advisory を返す。
  • AC2: advisory payload は block: false、observed_path、approved_replacement: "tmp/"、approved_temporary_roots、cleanup_required: true、policy_doc を含む。
  • AC3: local_main_branch_guard.py は branch / GitHub mutation blocker の責務を維持し、root temporary alias の deny logic を追加しない。
  • AC4: folder policy SSOT は tmp/、.claude/tmp/、.claude/worktrees/、.tmp/、.temp/、.tmp-* の folder class / git tracking / lifecycle / cleanup authority / publication rule を定義する。
  • AC5: cleanup safety rules は tmp/ / .claude/tmp/ / .claude/worktrees/ の root 全体削除を自動実行対象にせず、ownership marker に基づく削除可能性判定を 実装: root temporary residue cleanup classifier を構造化する #1417 の follow-up として明記する。
  • AC6: post-merge-cleanup docs は root temporary residue を report_only として分類し、marker 不明の .tmp/** を自動削除しないことを明記する。
  • AC7: Claude / Codex parity tests は advisory-only behavior、exit code 0、hookSpecificOutput.additionalContext、no-match silent/fail-open behavior を検証する。
  • AC8: .gitignore と docs は .claude/tmp/ の扱いを一致させ、許可済み local temporary workspace として使う場合の終了時削除または報告ルールを明記する。

Runtime Verification Applicability

runtime_verification_applicability:
  decision: immediate
  reason: "temporary directory advisory policy は hook tests と docs grep で即時検証できる"
  applicable_acs:
    - AC1
    - AC2
    - AC3
    - AC4
    - AC5
    - AC6
    - AC7
    - AC8
  execution_environment: "local WSL2 Ubuntu 24.04 / repo hook tests"
  skip_conditions:
    - "ローカル依存関係が欠落し、hook test harness が起動できない場合"
  fallback_policy: "build cache 等との衝突が判明した場合は対象 directory を allowlist / advisory / report-only に分離し、cleanup classifier は #1417 で扱う"
  artifact_requirements:
    - "Claude / Codex hook parity test output"
    - "folder policy docs grep output"

Verification Commands

# AC1
# baseline-expect: fail
$ rg -n "root_temporary_residue_advisory" .claude/settings.json .codex/hooks.json

# AC2
# baseline-expect: fail
$ rg -n "approved_replacement" scripts/agent-guards/root_temporary_residue_policy.py schemas/repo_temp_folder_advice_v1.schema.json

# AC3
# baseline-expect: pass
$ rg -n "classification: blocker" docs/dev/hook-boundaries.md

# AC4
# baseline-expect: fail
$ rg -n "REPOSITORY_FOLDER_POLICY_V1" .gitignore

# AC5
# baseline-expect: fail
$ rg -n "TEMP_CLEANUP_SAFETY_RULES_V1" .claude/skills/post-merge-cleanup/SKILL.md

# AC6
# baseline-expect: fail
$ rg -n "root temporary residue" .claude/skills/post-merge-cleanup/SKILL.md

# AC7
# baseline-expect: fail
$ rg -n "REPO_TEMP_FOLDER_ADVICE_V1" .claude/hooks/tests/test_root_temporary_residue_advisory.py tests/codex/test_root_temporary_residue_advisory.py

# AC8
# baseline-expect: fail
$ rg -n "repo-approved local temporary workspace" .gitignore

Allowed Paths

  • .claude/settings.json
  • .codex/hooks.json
  • .claude/hooks/root_temporary_residue_advisory.sh
  • .codex/hooks/root_temporary_residue_advisory.sh
  • scripts/agent-guards/root_temporary_residue_policy.py
  • scripts/agent-guards/tests/test_root_temporary_residue_policy.py
  • .claude/hooks/tests/test_root_temporary_residue_advisory.py
  • tests/codex/test_root_temporary_residue_advisory.py
  • schemas/repo_temp_folder_advice_v1.schema.json
  • docs/dev/repository-folder-policy.md
  • .claude/skills/post-merge-cleanup/SKILL.md
  • docs/dev/hook-boundaries.md
  • docs/dev/agent-skill-boundaries.md
  • .gitignore
  • AGENTS.md
  • scripts/check_hook_boundaries.py
  • scripts/check-codex-agents.mjs
  • scripts/check_codex_agent_config.py
  • scripts/session-recording/validate-codex-hooks.mjs
  • .github/ci/python-test-plan.json

Stop Conditions

  • .tmp/ 作成を block する仕様へ変更が必要と判明した場合
  • local_main_branch_guard.py に root temporary alias deny logic を入れないと実装不能と判明した場合
  • Allowed Paths 外の変更が必要と判明した場合
  • build / test cache directory の仕様変更が必要と判明した場合
  • .claude/tmp/ の全面禁止が必要と判明した場合
  • repo 全体の未追跡ファイル sweep が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合

Required Skills

  • Hook policy
  • Documentation

Required Design References

  • docs/dev/hook-boundaries.md
  • docs/dev/agent-skill-boundaries.md
  • .claude/skills/post-merge-cleanup/SKILL.md
  • AGENTS.md
  • .gitignore

Scope Delta

  • Anchor comment issuecomment-4918012236 に基づき、旧 contract の deny / fail-closed 前提を advisory-only / exit code 0 / additionalContext へ修正する。
  • 新 hook を正攻法で登録できるよう、Allowed Paths に hook registration、wrapper、policy producer、schema、parity tests、folder policy docs を追加する。
  • .claude/tmp/ は本文だけの例示から repo policy 上の明文化対象へ昇格する。

Delivery Rule

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    on Jul 8, 2026
  2. squne121 commented on Jul 8, 2026

    @squne121
    OwnerAuthor

    you asked

    message time: 2026-07-09 02:58:26

    #1404
    内容について関連Issue、PR、リポジトリ資産、コメントを参照した上で敵対的レビューして。
    取り扱う技術や配布物の実装をWEB検索し高品質化してほしい。

    リポジトリで認められているフォルダ運用は何を基準とするか。
    リポジトリで認められているフォルダの破壊をどのように防ぐか。
    リポジトリで認められているテンポラリフォルダでAIエージェントが作業するようにどのようにhookから案内するか。.tmp/のようなフォルダを作ろうとした時にtmp/を使うように案内する。
    しかし、作業をブロックはしない。
    フォルダ運用の変更が必要になったとき、リポジトリで認められているフォルダ運用を修正するような動線が必要。


    chatgpt response

    対象Issueと関連Issue/PR、コメント、既存ルール・hook/CI設定を横断確認し、リポジトリ実態に照らして敵対的にレビューします。外部のhook実装やAIエージェント向けガードレール例も比較し、設計上の抜けを重点確認します。


    chatgpt response

    Issue #1404自体にコメントはなく、本文契約を一次情報として扱います。親Issue #1395とPR #1399をたどり、特に.tmp/ residue対策としての位置づけを確認します。


    chatgpt response

    判定: REQUEST_CHANGES

    #1404 は目的自体は妥当です。ただし、現行 contract のまま実装すると、依頼要件と衝突します。最大の問題は、Issue 本文の Outcome が「.tmp/ や類似の未追跡一時フォルダを作成しようとした場合、hook または documented guard が fail-closed で止める」としている一方で、今回の要件は「tmp/ を使うよう案内する。しかし、作業をブロックはしない」です。ここを直さずに実装すると、hook は要求と逆方向に進みます。#1404 は AC1 でも root .tmp/ 作成を “deny または cleanup-required” としており、非ブロッキング誘導が契約上の正本になっていません。

    #1404 自体にはコメントがないため、判断材料は Issue 本文、親 Issue #1395、派生元 PR #1399、既存 hook/docs/config です。#1395 は exact executor / repair hint / hook docs drift の問題を扱って closed 済みで、PR #1399 は direct script 誘導を exact skill_runtime_exec.py --command-id preflight.run 誘導へ直し、Claude/Codex parity tests と docs を整合させて merged されています。

    P0-1: 「止める hook」と「ブロックしない案内」が契約上衝突している

    Claude Code hook では exit code 2 が PreToolUse の tool call をブロックします。公式 docs も exit 2 を blocking error とし、PreToolUse では tool call を止めると説明しています。(Claude Platform Docs) Codex でも PreToolUse は deny shape または exit code 2 でブロックできる一方、ブロックせずに model-visible context を追加するには hookSpecificOutput.additionalContext を返す設計です。(OpenAI 開発者)

    したがって #1404 の Outcome / AC1 は次に変更すべきです。

    ## Outcome
    agent が repo root に `.tmp/` や類似の未追跡一時フォルダを作成しようとした場合、
    hook は作業を block せず、`tmp/` または repo-approved temporary area を使うよう
    REPO_TEMP_FOLDER_ADVICE_V1 を additionalContext として返す。
    実行後に root temporary residue が残った場合は cleanup-required として分類し、
    post-merge-cleanup で削除対象または報告対象に deterministic に分類する。
    
    ## Acceptance Criteria
    - [ ] AC1: `.tmp/` / `.temp/` / `.tmp-*` 等の root temporary directory 作成コマンドは block されず、
          `tmp/` への誘導 advisory を返す。
    - [ ] AC1b: 同じケースで hook exit code は 0 であり、Claude/Codex 両方で tool call を止めない。

    deny または cleanup-required ではなく、advisory または cleanup-required に寄せる必要があります。

    P0-2: 既存 local_main_branch_guard はこの用途の正しい器ではない

    local_main_branch_guard.py は root checkout の branch drift を止めるための blocker hook です。ファイル冒頭も「local root checkout を default branch から変更する Bash command を block」と定義し、hook mode の exit code は allow=0 / block=2 です。 hook-boundaries でも local_main_branch_guard は classification: blocker / fail_policy: fail_closed / PreToolUse Bash として登録されています。

    しかも現行実装の最後は、分類不能な non-branch command を unknown_non_branch_command_allowed として allow します。つまり単純な mkdir .tmp は branch mutation ではないため、既存 guard の思想では基本的に block されません。

    このため、#1404 でやるべき実装は local_main_branch_guard に fail-closed deny を追加することではありません。正しい方向は、既存の ci_test_performance_advisory.sh と同型の non-blocking / fail-open advisory hook を追加することです。この既存 advisory hook は hookSpecificOutput.additionalContext を返し、常に exit 0 で、tool call を止めない設計になっています。

    P0-3: #1404 の Allowed Paths では、新 hook の正規実装に足りない

    Claude 側の hook は .claude/settings.json に登録されており、Codex 側は .codex/hooks.json に登録されています。現行設定では Claude PreToolUse に local_main_branch_guard.sh、worktree_scope_guard.sh、ci_test_performance_advisory.sh などが登録されています。 Codex 側も PreToolUse で local main guard、worktree scope guard、session recording、CI/test advisory を登録しています。

    #1404 の Allowed Paths には .claude/settings.json、.codex/hooks.json、新しい .claude/hooks/*、新しい .codex/hooks/*、新しい schema file が含まれていません。 したがって、ブロックしない advisory hook を正攻法で入れるなら、Allowed Paths を拡張するか、別 Issue に分割する必要があります。

    最小の修正案は次です。

    ## Allowed Paths 追加候補
    - `.claude/settings.json`
    - `.codex/hooks.json`
    - `.claude/hooks/root_temporary_residue_advisory.sh`
    - `.codex/hooks/root_temporary_residue_advisory.sh`
    - `scripts/agent-guards/root_temporary_residue_policy.py`
    - `scripts/agent-guards/tests/test_root_temporary_residue_policy.py`
    - `schemas/repo_temp_folder_advice_v1.schema.json`

    既存 local_main_branch_guard.py に詰め込む場合でも、blocker hook から non-blocking advisory を返す混在設計になるため、hook-boundaries の責務分類も更新が必要です。

    P0-4: 「リポジトリで認められているフォルダ運用」の基準が未定義

    現状、tmp/ が repo-approved temporary area である根拠は複数あります。.gitignore は tmp/ を NotebookLM local assets および project-local tmp working files として ignore し、issue backups / intermediate body / reviewer feedback などの作業領域だと説明しています。 既存 hook policy も gh issue create --body-file tmp/... や gh issue view ... > tmp/<file> を canonical tmp path として検証しています。

    一方で、#1404 は .claude/tmp/ を repo-approved temporary area の例として挙げていますが、少なくとも確認した .gitignore では .claude/worktrees/ と .claude/plans/ は ignore されているものの、.claude/tmp/ は明示されていません。 つまり、.claude/tmp/ を許可するなら、Issue 本文だけでなく SSOT 側に明記する必要があります。

    基準は「名前」ではなく、次の属性で定義すべきです。

    REPOSITORY_FOLDER_POLICY_V1:
      path: "tmp/"
      class: "repo_approved_temporary_workspace"
      root_visibility: "repo_root"
      git_tracking: "ignored"
      owner: "agent_or_skill_session"
      allowed_use:
        - "issue body intermediate files"
        - "reviewer feedback materialization"
        - "temporary gh --body-file input"
        - "readonly export target"
      cleanup_rule: "delete own session files before finish, otherwise report"
      publish_rule: "never include in release/deploy artifacts unless explicitly whitelisted"
      destructive_cleanup_allowed: "own session subdir only"
    
      path: ".claude/tmp/"
      class: "claude_local_temporary_workspace"
      status: "allowed only if documented and ignored"
      cleanup_rule: "same as tmp/, but not a general repo-shared artifact surface"
    
      path: ".tmp/"
      class: "root_temporary_alias_denied"
      hook_behavior: "advisory_only"
      replacement: "tmp/"
      cleanup_rule: "cleanup_required_or_report"

    P0-5: 許可済みフォルダの「破壊」を防ぐ制御が不足している

    tmp/ を勧めるだけでは不十分です。次に起きる事故は、cleanup が rm -rf tmp のように許可済み作業領域全体を壊すことです。既存 post-merge-cleanup は未追跡ファイルを「報告対象(削除しない)」として扱い、この時点では削除しないと明記しています。 branch/worktree 削除も bare git ではなく cleanup_exec.py の認可境界を通す設計です。

    これと同じ思想で、temporary folder cleanup も次を必須にしてください。

    TEMP_CLEANUP_SAFETY_RULES_V1:
      never_delete:
        - "tmp/"
        - ".claude/tmp/"
        - ".claude/worktrees/"
        - ".git/"
        - "tracked files"
      may_delete_without_human:
        - "tmp/agent-sessions/<session-id>/** only when ownership marker matches"
      report_only:
        - ".tmp/**"
        - ".temp/**"
        - "tmp/** without ownership marker"
        - "any path with symlink traversal ambiguity"
      required_checks:
        - "relative path only"
        - "no NUL"
        - "no backslash path on POSIX policy"
        - "Path.resolve(strict=False)"
        - "resolved path is_relative_to approved root"
        - "git ls-files confirms untracked before deletion"

    既存コードには tmp/ confinement の良い前例があります。_is_safe_tmp_body_file() と _is_safe_tmp_redirect_dest() は、absolute path、path traversal、backslash、NUL を拒否し、Path.resolve(strict=False) と is_relative_to(tmp_root) で tmp/ 配下に閉じています。 ただしこれは --body-file / redirect の入力検証であって、cleanup の所有権や削除安全性までは保証しません。そこを #1404 の AC に追加すべきです。

    hook からの案内は HOOK_COMMAND_REPAIR_HINT_V1 ではなく advisory schema にする

    HOOK_COMMAND_REPAIR_HINT_V1 は block された command の repair hint です。hook_repair_hints.py も blocked_command_class / reason_code / suggested_command を返す構造で、block stderr から使われる設計です。 #1399 でも direct issue-refinement script を block した場合に exact executor を案内する用途で整備されています。

    .tmp/ は今回「ブロックしない」ので、repair hint ではなく advisory を新設すべきです。

    REPO_TEMP_FOLDER_ADVICE_V1:
      schema_version: 1
      block: false
      reason_code: "root_temporary_alias"
      observed_path: ".tmp/"
      approved_replacement: "tmp/"
      approved_temporary_roots:
        - "tmp/"
        - ".claude/tmp/"
      cleanup_required: true
      message_ja: "repo root の .tmp/ は残置ノイズになります。作業は tmp/ 配下に置き、終了時に削除または報告してください。"
      policy_doc: "docs/dev/repository-folder-policy.md"

    Claude/Codex の両方で、PreToolUse は additionalContext を使えば block せずにモデルへ文脈を渡せます。Claude Code は JSON stdout を exit 0 で処理し、additionalContext をモデル文脈へ追加できます。(Claude Platform Docs) Codex も hookSpecificOutput.additionalContext を返せば model-visible context を追加し、block しないと公式 docs で説明しています。(OpenAI 開発者)

    既存の ci_test_performance_advisory.sh はこの実装パターンをすでに採用しており、block: false、hookSpecificOutput.additionalContext、exit 0 の具体例として流用できます。

    実装方針

    1. PreToolUse advisory

    対象は simple Bash command と file tool 入力です。Codex docs は PreToolUse が Bash / apply_patch / MCP tool calls を intercept できるが、完全な enforcement boundary ではないと説明しています。(OpenAI 開発者) これは今回の「止めない案内」には適していますが、「完全防止」の証拠には使えません。

    検出例:

    mkdir .tmp
    mkdir -p .tmp/foo
    install -d .tmp
    python script.py --out .tmp/result.json
    node tool.js --cache-dir .tmp/cache
    Write/Edit target: .tmp/foo.json
    apply_patch creates: .tmp/foo.json
    

    動作:

    match あり:
      stdout: hookSpecificOutput.additionalContext = "REPO_TEMP_FOLDER_ADVICE_V1 {...}"
      exit: 0
    
    match なし:
      stdout: none
      exit: 0
    
    internal error:
      stdout: none
      exit: 0
    

    2. Stop / PostToolUse residue scan

    PreToolUse ではすべての作成経路を捕捉できません。PostToolUse は「すでに tool が実行された後」なので副作用を取り消せず、Claude docs でも PostToolUse は exit 2 でも tool は既に実行済みで stderr を見せるだけです。(Claude Platform Docs) したがって Stop または PostToolUse で git ls-files --others --exclude-standard -z を使って root .tmp/ / .temp/ residue を検出し、cleanup-required advisory を返すのが安全です。

    分類は次のようにします。

    ROOT_TEMP_RESIDUE_CLASSIFICATION_V1:
      denied_alias_residue:
        - ".tmp/"
        - ".temp/"
        - ".tmp-*"
      approved_temp_residue:
        - "tmp/"
        - ".claude/tmp/"
      action:
        denied_alias_residue: "report cleanup_required; do not auto-delete unless ownership marker matches"
        approved_temp_residue: "delete own session files or report"

    3. post-merge-cleanup docs の更新

    post-merge-cleanup はすでに「未追跡ファイルは報告対象、削除しない」としています。 ここに root temporary residue の専用分類を追加します。

    root temporary residue:
    - `.tmp/`, `.temp/`, `.tmp-*` は repo-approved temporary area ではない。
    - 自動削除は ownership marker がある場合のみ。
    - marker がない場合は `unresolved_cleanup_items` に `root_temporary_residue` として報告する。
    - 次回作業では `tmp/` または `.claude/tmp/` を使うよう報告文に含める。

    配布物・artifact への混入対策

    .tmp/ は dot directory なので hidden file/folder 扱いです。GitHub Actions upload-artifact は hidden files をデフォルトでは無視しますが、include-hidden-files: true を使う場合は sensitive 情報の混入を避けるため validate/exclude が必要だと説明しています。(GitHub) hidden files は . で始まる file または . で始まる folder 配下の file と定義されています。(GitHub)

    したがって local hook は block しない一方で、配布物生成・preview deploy・release artifact の前段では .tmp/** を明示除外または fail してよいです。これは「AI 作業をブロックしない」と「配布物を汚さない」を分離するためです。

    直接回答

    リポジトリで認められているフォルダ運用は何を基準とするか

    基準は path name 単体ではなく、次の 6 属性です。

    属性 判定内容
    folder_class source / generated / cache / temp / artifact / managed worktree
    git_tracking tracked / ignored / untracked tolerated / prohibited residue
    owner repo / skill / agent session / external tool
    lifecycle persistent / per-PR / per-issue / per-session / disposable
    publication deploy/release artifact に入れてよいか
    cleanup_authority 誰が、どの条件で、どこまで削除できるか

    現時点で明確に repo-approved temporary area と言えるのは tmp/ です。.gitignore と hook の tmp/ path validation がそれを裏付けています。 .claude/tmp/ は #1404 本文では許可例ですが、repo asset 側の SSOT に未固定なので、今回の docs 更新で明文化が必要です。

    リポジトリで認められているフォルダの破壊をどう防ぐか

    tmp/ や .claude/tmp/ 自体を削除対象にしないことです。削除可能なのは「自分の session marker を持つ subdirectory」だけに限定します。tracked file、symlink traversal、ownership 不明、root approved directory 全体削除はすべて report-only にします。

    実装上は次を必須にします。

    - relative path only
    - no NUL / no backslash
    - resolve(strict=False)
    - is_relative_to(approved root)
    - git ls-files で tracked でないことを確認
    - tmp/<session-id>/.owner.json の一致確認
    - rm -rf tmp または rm -rf .claude/tmp は常に拒否または human escalation
    

    .tmp/ を作ろうとした時に hook からどう案内するか

    PreToolUse で block せず、additionalContext に advisory を返します。

    {
      "hookSpecificOutput": {
        "hookEventName": "PreToolUse",
        "additionalContext": "REPO_TEMP_FOLDER_ADVICE_V1 {\"block\":false,\"observed_path\":\".tmp/\",\"approved_replacement\":\"tmp/\",\"message_ja\":\"repo root の .tmp/ ではなく tmp/ を使ってください。作業後は削除または報告してください。\"}"
      }
    }

    exit code は 0 固定です。Claude/Codex ともにこの形は既存 advisory hook と同じ思想で、作業を止めずに agent steering できます。

    フォルダ運用の変更が必要になった時の動線

    docs/dev/repository-folder-policy.md のような SSOT を置き、変更時は必ず次を同一 PR に含めるべきです。

    1. folder policy SSOT の更新
    2. hook policy の allow/advisory/cleanup 分類更新
    3. Claude/Codex parity tests 更新
    4. AGENTS.md または agent-skill-boundaries.md への運用導線追記
    5. post-merge-cleanup の report/delete 分類更新
    6. 配布物 artifact 除外ルールの確認
    

    ただし #1404 の現在の Allowed Paths では、この変更動線を完全には実装できません。新 SSOT doc、hook registration、schema、new advisory hook を入れるなら Allowed Paths 拡張が必要です。Allowed Paths を広げない場合は、#1404 は docs/test だけの暫定対応に縮小し、新 hook は follow-up Issue に分割するのが安全です。

    #1404 の修正文案

    ## Outcome
    agent が repo root に `.tmp/` や類似の未追跡 temporary directory を作成しようとした場合、
    Claude/Codex hooks は tool call を block せず、`tmp/` または repo-approved temporary area を使うよう
    `REPO_TEMP_FOLDER_ADVICE_V1` を model-visible context として返す。
    作業後に root temporary residue が残った場合、post-merge-cleanup は削除対象・報告対象・許可済み残置を
    deterministic に分類する。
    
    ## In Scope
    - root temporary alias (`.tmp/`, `.temp/`, `.tmp-*`) の advisory-only hook policy
    - `tmp/` / `.claude/tmp/` / `.claude/worktrees/` 等の folder class SSOT
    - approved folder を破壊しない cleanup safety rules
    - Stop/PostToolUse residue scan
    - Claude/Codex advisory parity tests
    - post-merge-cleanup の root temporary residue report rules
    
    ## Out of Scope
    - local hook による `.tmp/` 作成 block
    - repo-wide untracked sweep
    - `tmp/` または `.claude/tmp/` の wholesale deletion
    - build/test cache directory の blanket ban
    
    ## Acceptance Criteria
    - [ ] AC1: `mkdir .tmp` / `mkdir -p .tmp/foo` は Claude/Codex hook で block されず、exit 0 で advisory を返す。
    - [ ] AC2: advisory は `tmp/` を approved replacement として案内する。
    - [ ] AC3: `tmp/` / `.claude/tmp/` の wholesale deletion を案内しない。
    - [ ] AC4: post-merge-cleanup docs は root temporary residue を `cleanup_required` または `report_only` に分類する。
    - [ ] AC5: folder policy SSOT に approved / denied / report-only temporary roots が明記される。
    - [ ] AC6: Claude/Codex parity tests が advisory-only と non-blocking exit を検証する。

    この形なら、依頼された「案内するがブロックしない」「許可済みフォルダを壊さない」「フォルダ運用変更時の動線を持つ」を満たせます。

  3. squne121 commented on Jul 8, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  4. squne121 commented on Jul 9, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-07-09T12:54:28Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1404
      body_sha256: "sha256:e2aaf1d2e08fd5b15e464087c9cfe6b9851222686362d8ee44c846844444ad47"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: ensure_contract_snapshot_auto
  5. squne121 commented on Jul 9, 2026

    @squne121
    OwnerAuthor

    implement-issue: publish blocked (2026-07-09T00:00:00Z)

    • status: blocked
    • issue: 実装: agent の root temporary residue を hook と docs で防止する #1404
    • local_commit: 1621c835425a8957e946ecb97e581e0ee06bf6ad
    • worktree: /home/squne/projects/LOOP_PROTOCOL/.claude/worktrees/issue-1404-agent-root-temporary-residue-hook-docs
    • branch: worktree-issue-1404-agent-root-temporary-residue-hook-docs
    • verification: Issue Verification Commands 8/8 PASS, pytest 22 PASS, py_compile PASS
    • blocker: branch publish が repo-side remote_write_requires_approval guard により停止し、remote branch / Draft PR を作成できない
    • note: PR body validator は通過済み。publish lane の許可または代替 publish 経路が必要
  6. squne121 commented on Jul 9, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-07-09T21:59:12Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1404
      body_sha256: "sha256:9802bb87fb2d36e5e51485bb8078a454cd5348fa2bcd34d67da67a8ce5ee8c7b"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: manual_refresh_after_allowed_paths_update
  7. squne121 commented on Jul 9, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-07-09T22:14:52Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1404
      body_sha256: "sha256:661944f184a31882b8fb648a1eb394e9abc65c7ed3b5a166744ae6c124849c93"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: manual_refresh_after_ci_topology_validator_scope_update

    Allowed Paths に Codex hook topology validator と python-test plan の同期対象を追加した後の fresh status: go snapshot です。

  8. squne121 commented on Jul 10, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-07-10T11:29:18Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1404
      body_sha256: "sha256:29b722a95870d1a9daa7674b0db65f910490906d1a22d52d24ff0cd801669dc6"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: manual_refresh_after_owner_request_changes_scope_narrowing

    Owner review comment #1407 (comment) を受け、cleanup classifier を #1417、schema catalog registration を #1418 に分離した後の fresh status: go snapshot です。

  9. squne121 commented on Jul 10, 2026

    @squne121
    OwnerAuthor

    impl-review-loop: 完了 (2026-07-10T11:43:33Z)

    IMPL_REVIEW_LOOP_RESULT_V1:
      schema_version: 1
      status: draft_pr_ready
      draft_pr_ready: true
      github_merge_ready: false
      github_merge_state_status: DRAFT
      merge_ready: true
      pr_url: "https://github.com/squne121/loop-protocol/pull/1407"
      head_sha: "478e564fc5225d15f43af3d727d3d9c82f32c898"
      issue_number: 1404
      termination_reason: approved
      iteration: 1
      required_auto_actions: []
      contract_snapshot_url: "https://github.com/squne121/loop-protocol/issues/1404#issuecomment-4934832124"
      test_verdict_url: "https://github.com/squne121/loop-protocol/pull/1407#issuecomment-4934895473"
      loop_verdict_url: "https://github.com/squne121/loop-protocol/pull/1407#pullrequestreview-4671093389"
      owner_request_changes_url: "https://github.com/squne121/loop-protocol/pull/1407#issuecomment-4934714794"
      ci_required_status: passed
      allowed_paths_gate:
        status: ok
        changed_files_source: git_diff_name_status_find_renames_z
      human_next_action: mark_ready_for_review_or_merge
    
    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: impl-review-loop
      follow_up_issues:
        - request_dedupe_key: "issue-1404-root-temp-cleanup-classifier"
          status: created
          issue:
            number: 1417
            url: "https://github.com/squne121/loop-protocol/issues/1417"
          reason: "deterministic cleanup classifier / ownership marker は #1404 から分離"
        - request_dedupe_key: "issue-1404-repo-temp-folder-advice-schema-catalog"
          status: created
          issue:
            number: 1418
            url: "https://github.com/squne121/loop-protocol/issues/1418"
          reason: "repo_temp_folder_advice/v1 schema catalog registration は #1404 から分離"
  10. squne121 commented on Jul 10, 2026

    @squne121
    OwnerAuthor

    post-merge-cleanup: 完了 (2026-07-10T11:49:30Z)

    POST_MERGE_CLEANUP_REPORT_V1:
      schema: POST_MERGE_CLEANUP_REPORT_V1
      status: partial
      generated_at: "2026-07-10T11:49:30Z"
      generated_by: post-merge-cleanup
      human_review_required: true
      cleaned_branches: []
      cleaned_worktrees:
        - "/home/squne/projects/LOOP_PROTOCOL/.claude/worktrees/issue-1404-agent-root-temporary-residue-hook-docs"
      unresolved_cleanup_items:
        - item: "branch delete が cleanup_exec で拒否された"
          branch: "worktree-issue-1404-agent-root-temporary-residue-hook-docs"
          reason: "branch_delete_failed: error: the branch 'worktree-issue-1404-agent-root-temporary-residue-hook-docs' is not fully merged."
          local_ref_exists: true
          remote_ref_exists: true
          note: "PR は MERGED だが squash merge のため git branch -d の ancestry 判定では fully merged にならない。強制削除は自動実行していない。"
      parent_issue_status:
        parent_issue_number: 1395
        all_children_closed: false
        recommended_action: keep_open
        note: "open child が残っているため parent close はしない。"
      superseded_prs:
        - number: 1410
          title: "fix: agent publish lane safety stop (#1402)"
          url: "https://github.com/squne121/loop-protocol/pull/1410"
          action: "no_action"
          note: "検索候補。別 issue の PR なので close しない。"
        - number: 1412
          title: "feat: reviewer_claim_replay.py に VCP_BROAD_SEARCH_PATH_UN taxonomy mapping を追加する"
          url: "https://github.com/squne121/loop-protocol/pull/1412"
          action: "no_action"
          note: "検索候補。別 issue の PR なので close しない。"
      follow_up_issue_requests:
        - request_dedupe_key: "issue-1404-root-temp-cleanup-classifier"
          status: reused_open
          issue:
            number: 1417
            url: "https://github.com/squne121/loop-protocol/issues/1417"
          reason: "既存 open issue のため追加起票しない。"
        - request_dedupe_key: "issue-1404-repo-temp-folder-advice-schema-catalog"
          status: reused_open
          issue:
            number: 1418
            url: "https://github.com/squne121/loop-protocol/issues/1418"
          reason: "既存 open issue のため追加起票しない。"
      stash_restored: n/a
      stash_entry_ref: null
      warnings:
        - "local/remote branch は残存。強制削除は人間判断。"
      errors: []
    
    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: post-merge-cleanup
      follow_up_issues:
        - request_dedupe_key: "issue-1404-root-temp-cleanup-classifier"
          status: reused_open
          issue:
            number: 1417
            url: "https://github.com/squne121/loop-protocol/issues/1417"
          reason: "PR #1407 で follow-up 済み。"
        - request_dedupe_key: "issue-1404-repo-temp-folder-advice-schema-catalog"
          status: reused_open
          issue:
            number: 1418
            url: "https://github.com/squne121/loop-protocol/issues/1418"
          reason: "PR #1407 で follow-up 済み。"
      note_only_observations:
        - dedupe_key: "post-merge-cleanup-1407-branch-delete-refused"
          source_url: "https://github.com/squne121/loop-protocol/pull/1407"
          source_note_id: "cleanup_exec_branch_delete_failed"
          summary: "対象 worktree は削除済みだが squash merge ancestry 判定により branch delete は拒否された。"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions