Skip to content

worktree_scope_guard に local main scratch 出力先の安全な例外 (LOCAL_MAIN_SCRATCH_ALLOW_V1) を追加する #974

Closed

Description

@squne121

背景

#960 / PR #971 で worktree_scope_guard が PreToolUse で active issue worktree 外の Write/Edit/MultiEdit と mutating Bash を fail-closed に block する。再レビューで判明した fail-open(外部 absolute path への shell file-write 等)を #971 で塞ぐと guard はより厳格になる。

その結果、LOOP_ISSUE_NUMBER 等で active issue context が解決されたまま local main checkout 上で作業すると、.gitignore 対象の生成物(artifacts/, playwright-report/, test-results/, coverage/, .cache/ 等)への書込も block され、正当な作業が止まる懸念がある。

Outcome

worktree_scope_guard.py に LOCAL_MAIN_SCRATCH_ALLOW_V1 判定関数が実装され、local main context(cwd_realpath == project_root_realpath かつ current_branch == main/default かつ cwd が linked issue worktree 内でない)からの Write/Edit/MultiEdit が repo-local .gitignore 由来の gitignored & untracked な safe_scratch_prefix 配下のみ allow される。tracked / global-only ignore / sensitive path / symlink component を含む target への書込は block されたままになる。

目的

main 汚染防止を維持したまま、明示的に安全な scratch 出力先への local main 書込のみを許可する例外 LOCAL_MAIN_SCRATCH_ALLOW_V1 を追加し、作業継続性と guard の安全性を両立する。

設計方針

.gitignore 単独での blanket allow は危険(.gitignore は tracked file に効かず、.env/local config/secret cache を含み得る。git add -f で強制 stage も可能)。そのため以下の複合条件をすべて満たす direct Write/Edit/MultiEdit のみ allow する(Phase 1)。

local_main_context 判定(3 条件すべて必須)

cwd_realpath == project_root_realpath
current_branch in [main, repo_default_branch]
cwd is not inside any linked issue worktree (git worktree list --porcelain -z で検証)

target 判定(すべて必須)

  • target_realpath が project_root_realpath 内
  • target_realpath が expected_issue_worktree / .git/** / .claude/worktrees/** 外
  • normalized relpath が explicit safe_scratch_prefix 配下(component boundary 照合、文字列 prefix 不可)
  • safe_scratch_prefix は実装時に repo-local .gitignore へ追加する
  • git ls-files --error-unmatch -- <rel> が nonzero(tracked/index 入りを reject)
  • git check-ignore -v -- <rel> が repo-local .gitignore 由来(global excludes / .git/info/exclude のみでは不十分)
  • sensitive path denylist に非該当(.env*, *.pem/key/p12/pfx, *token*/*secret*/*credential*, .npmrc/.pypirc/.netrc, .ssh/**, .config/gh/**)
  • path component に既存 symlink を含まない(safe root が存在かつ非 symlink、parent が非 symlink、target が存在する場合は非 symlink)

Phase 分割

git/gh/package manager mutation

scratch 例外を適用しない(常に block)。

非ゴール

関連

Acceptance Criteria

  • AC1: cwd_realpath == project_root_realpath かつ current_branch == main/default_branch かつ cwd が linked issue worktree 内でない 三条件をすべて満たすときのみ local main scratch context と認める
  • AC2: safe_scratch_prefix 配下の repo-local .gitignore 由来 gitignored & untracked path への local main からの Write/Edit/MultiEdit を allow する(prefix は実装時に .gitignore へ追加される)
  • AC3: safe-prefix 外 / tracked / global-only ignore / sensitive path / symlink component を含む target への local main 書込は引き続き block する
  • AC4: prefix containment は realpath/commonpath を使い path component boundary で照合する(artifacts_evil/ や artifacts/../README.md を block)
  • AC5: symlink policy: safe_root が存在かつ非 symlink、target への path component に既存 symlink を含む場合は fail-closed
  • AC6: sensitive path denylist(.env*, *.pem/key/p12/pfx, *token*/*secret*/*credential*, .npmrc/.pypirc/.netrc, .ssh/**, .config/gh/**)を含む target は block
  • AC7: git ls-files --error-unmatch -- <rel> が 0 を返す(tracked/index 入り)場合は block
  • AC8: git check-ignore -v -- <rel> で source が repo-local .gitignore 由来でない(global excludes / .git/info/exclude のみ)場合は block
  • AC9: git/gh/package manager mutation には scratch 例外を適用しない
  • AC10: Phase 1 として Write/Edit/MultiEdit のみを対象とし、Bash write exception は Phase 2 follow-up issue に分離する
  • AC11: pytest behavioral harness(実 git repo + real issue worktree 作成、subprocess 経由で guard wrapper 呼出)で以下を検証する:
    • allow_local_main_write_to_repo_ignored_untracked_playwright_report
    • allow_local_main_write_to_repo_ignored_untracked_test_results
    • block_safe_prefix_not_in_repo_gitignore
    • block_global_gitignore_only_match
    • block_tracked_file_under_safe_prefix
    • block_artifacts_prefix_sibling_artifacts_evil
    • block_artifacts_dotdot_readme
    • block_symlink_safe_root_to_outside
    • block_symlink_parent_component
    • block_existing_target_symlink
    • block_sensitive_dotenv_under_artifacts
    • block_sensitive_npmrc_under_cache
    • block_write_when_cwd_inside_issue_worktree
    • block_write_when_branch_is_issue_branch_not_main
    • block_write_inside_dot_git_even_if_ignored
    • block_write_inside_claude_worktrees_even_if_ignored
    • block_git_add_force_ignored_scratch_file

Allowed Paths

  • .claude/hooks/worktree_scope_guard.py
  • .claude/hooks/tests/test_local_main_scratch_allow.py
  • .gitignore

Verification Commands

# AC1
$ uv run pytest .claude/hooks/tests/test_local_main_scratch_allow.py -v -k "local_main_context or cwd_inside_issue_worktree or branch_is_issue_branch"
# AC2
$ uv run pytest .claude/hooks/tests/test_local_main_scratch_allow.py -v -k "allow_local_main"
# AC3
$ uv run pytest .claude/hooks/tests/test_local_main_scratch_allow.py -v -k "block_safe_prefix_not or block_tracked or block_global or block_sensitive or block_symlink or block_write"
# AC4
$ uv run pytest .claude/hooks/tests/test_local_main_scratch_allow.py -v -k "artifacts_evil or dotdot"
# AC5
$ uv run pytest .claude/hooks/tests/test_local_main_scratch_allow.py -v -k "symlink"
# AC6
$ uv run pytest .claude/hooks/tests/test_local_main_scratch_allow.py -v -k "sensitive"
# AC7
$ uv run pytest .claude/hooks/tests/test_local_main_scratch_allow.py -v -k "tracked"
# AC8
$ uv run pytest .claude/hooks/tests/test_local_main_scratch_allow.py -v -k "global_gitignore"
# AC9
$ uv run pytest .claude/hooks/tests/test_local_main_scratch_allow.py -v -k "git_add_force or git_mutation"
# AC10
$ uv run pytest .claude/hooks/tests/test_local_main_scratch_allow.py -v -k "write_exception or bash_exception"
# AC11
$ uv run pytest .claude/hooks/tests/test_local_main_scratch_allow.py -v

# preflight-scope: runtime_only
$ test -f .claude/hooks/worktree_scope_guard.py

# preflight-scope: runtime_only
$ rg -n "LOCAL_MAIN_SCRATCH_ALLOW_V1|local_main_scratch" .claude/hooks/worktree_scope_guard.py

# preflight-scope: runtime_only
$ rg -n "playwright-report|test-results|artifacts" .gitignore

# preflight-scope: runtime_only
$ uv run pytest .claude/hooks/tests/ -v --ignore=.claude/hooks/tests/test_local_main_scratch_allow.py

Runtime Verification Applicability

  • decision: deferred
  • reason: worktree_scope_guard.py への LOCAL_MAIN_SCRATCH_ALLOW_V1 実装が未完了のため、behavioral harness(pytest)は現時点で実行不可。実装完了後に uv run pytest で検証する。
  • deferred_destination:
  • deferred_verification_condition: worktree_scope_guard.py に LOCAL_MAIN_SCRATCH_ALLOW_V1 判定関数が実装され、test_local_main_scratch_allow.py が存在すること

Stop Conditions

  • worktree_scope_guard.py に LOCAL_MAIN_SCRATCH_ALLOW_V1 判定関数が実装され、AC1..AC11 の pytest が全 pass
  • .gitignore に Phase 1 safe_scratch_prefix エントリが追加済み
  • 既存 worktree_scope_guard tests が退行しない
  • Phase 2(Bash exception)は本 Issue の scope 外

依存 / ブロック

Activity

  1. added
    enhancement
    on Jun 17, 2026
  2. squne121 commented on Jun 17, 2026

    @squne121
    OwnerAuthor

    判定

    #974 は方向性として妥当。ただし、現行ドラフトのまま実装すると “safe scratch” 例外が権限穴になる可能性が高い。LOCAL_MAIN_SCRATCH_ALLOW_V1 は、単なる safe-prefix allowlist ではなく、local main checkout の厳密判定、repo-local ignore 判定、tracked/index 判定、symlink/TOCTOU 対策、secret denylist、#963 との依存順序まで含めた contract に格上げすべきです。

    #974 の問題意識は正しいです。#960 / PR #971 で worktree_scope_guard が導入され、active issue worktree 外の Write/Edit/MultiEdit と mutating Bash を fail-closed に遮断する設計になったため、main checkout 側の一時生成物まで巻き添えで止まる余地があります。#974 はその例外として LOCAL_MAIN_SCRATCH_ALLOW_V1 を提案しています。
    一方で、#974 自体にコメントはまだありません。PR #971 側のコメントには、レビューで AC1..AC15、75 pytest、mutation test、realpath + commonpath、bounded stderr、secret guard 先行などが確認された旨が残っています。

    根拠整理

    #960 の本体 contract は、「active issue worktree が存在するとき、worktree 外への Write/Edit/MultiEdit と mutating Bash を PreToolUse hook で block する」ことを目的にしています。expected worktree 解決は CLAUDE_PROJECT_DIR と settings.json 親解決を優先し、git rev-parse --show-toplevel を使わない、worktree catalog は git worktree list --porcelain -z、path containment は realpath / commonpath、malformed payload や git binary 不在は fail-closed、というかなり強い契約です。
    PR #971 はこれを実装済み・merge 済みで、変更ファイルは .claude/hooks/worktree_scope_guard.sh、.py、tests、settings の 4 ファイル、75 tests pass、pnpm test/typecheck/lint/build pass とされています。

    Claude Code の hook 仕様上、PreToolUse で exit 2 を返すと tool call はブロックされ、stderr がフィードバックとして渡されます。したがって、この guard は「注意喚起」ではなく実際の enforcement point です。ここに例外を足す場合、例外条件が policy の実体になります。([Claude Code]1)

    現行コードもこの前提に沿っています。Write/Edit/MultiEdit は active issue が解決され、対応 worktree が 0 件・複数件・不明の場合に block し、target が expected worktree 内にある場合だけ allow します。Bash も read-only は allow しますが、mutating/unknown は expected worktree 外 cwd、外部 cd / git -C、外部 write target、解析不能 write mutation を block します。
    Bash の write target 抽出は redirection、tee、sed -i / perl -i、Python/Node/Ruby one-liner などを対象にしており、変数・glob・command substitution 等の動的 destination は抽出しないため、caller 側で fail-closed になります。

    #963 は別 issue として、git add -A / git add . の常時 block と、git commit 前の cached diff の Allowed Paths 照合を扱います。#974 が「git/gh/package-manager mutation は例外にしない」「staged diff は #963 の責務」とするのは設計分割としては妥当ですが、#963 未実装のまま safe scratch 例外を入れると、ignored scratch artifact が git add -f で index に入るルートが残ります。 Git 公式 docs でも、ignored file は通常 git add されませんが --force/-f で追加できます。([Git]2)

    致命的な指摘

    1. local main の定義が足りない

    #974 は「local main scratch」と言っていますが、draft 条件は実質的に「target が project_root 内、expected worktree 外、safe-prefix 配下、ignored/untracked」までしか明示していません。これでは、どの checkout からの mutation なら “local main” と認めるのかが曖昧です。

    必要なのは以下のような判定です。

    local_main_context:
      cwd_realpath == project_root_realpath
      current_branch in [main, default_branch]
      cwd is not inside any linked issue worktree
      target is inside project_root_realpath
      target is outside .claude/worktrees/**
      target is outside expected_issue_worktree

    Git worktree は 1 repo に複数 working tree を関連付ける仕組みで、git worktree list --porcelain -z は機械処理用に NUL 区切りを提供します。#960 / PR #971 がこの形式に寄せたのは正しいですが、#974 の例外では「main checkout 自体」を catalog 上でどう特定するかを contract 化する必要があります。([Git]3)

    2. 現行 .gitignore と候補 safe-prefix が一致していない

    #974 の候補には artifacts/, playwright-report/, test-results/, coverage/, .cache/, .tmp/, tmp/ が挙がっていますが、現行 .gitignore で確認できるのは主に tmp/, .claude/worktrees/, .claude/plans/, .guard_shadow_log.jsonl, .venv/, __pycache__/, .pytest_cache/ などです。artifacts/, playwright-report/, test-results/, coverage/, .cache/, .tmp/ は現行 .gitignore には見えません。

    これは設計上かなり大きいです。#974 は git check-ignore -q -- <rel> を条件にしていますが、この条件を厳密に実装すると、候補 prefix の多くは allow されません。逆に .gitignore 条件を緩めると、「gitignored generated artifacts のみ」という #974 の安全根拠が崩れます。

    Git 公式 docs では、.gitignore は「意図的に untracked にするファイル」を指定するもので、すでに tracked なファイルには効きません。また ignore 判定は .gitignore だけでなく .git/info/exclude や global excludes など複数ソースを見ます。([git.github.io]4)
    したがって、単に git check-ignore -q が true なら allow では弱いです。git check-ignore -v で source を確認し、少なくとも repo 内の .gitignore 由来であることを要求する方が安全です。git check-ignore の公式 docs でも -v は matching pattern の source を出せるとされています。([Git]5)

    3. 「safe-prefix」だけでは secret を守れない

    artifacts/ や .cache/ は名前だけでは安全ではありません。以下はすべて safe-prefix 配下に置けてしまいます。

    artifacts/.env
    artifacts/token.txt
    .cache/gh/hosts.yml
    .cache/npm/_authToken
    playwright-report/data/*.zip
    test-results/**/trace.zip
    tmp/reviewer_feedback.md
    tmp/issue_*_backup_*.md
    

    現行 settings では secret boundary guard が worktree guard より前に配置されています。これは良い順序です。
    ただし #974 の例外は worktree guard 側に追加されるため、worktree guard 自身も safe-prefix だけでなく sensitive path denylist を持つか、既存 secret boundary の path 判定ロジックを共有すべきです。settings には .ssh, .config/gh, .env, printenv, gh secret などの deny が見えますが、scratch 配下の secret filename 全般を網羅しているとは読めません。

    4. symlink / TOCTOU が未解決

    PR #971 の realpath + commonpath 方針は startswith より正しいです。Python docs でも commonprefix() は文字単位で無効な path を返し得る一方、commonpath() は有効な common sub-path を返すと説明されています。([Python documentation]6)
    しかし、realpath() は存在しない component 以降をそのまま付ける挙動があり、存在しない target file をこれから作る場合、parent directory の symlink 差し替えや hook 判定後から write 実行までの TOCTOU が残ります。Python docs も、strict でない realpath() は最初に評価不能になった component 以降を unchanged で付けると説明しています。([Python documentation]6)

    最低限、scratch allow では以下を要求すべきです。

    symlink_policy:
      safe_root_must_exist: true
      safe_root_must_be_directory: true
      safe_root_must_not_be_symlink: true
      every_existing_parent_component_under_safe_root_must_not_be_symlink: true
      target_if_exists_must_not_be_symlink: true
      parent_if_missing_must_exist_and_not_be_symlink: true

    PreToolUse hook は atomic open を代行できないため完全な TOCTOU 排除はできません。ただし、既存 symlink component を reject するだけで、実用上の bypass はかなり減ります。

    5. tmp/ は広すぎる

    現行 .gitignore は tmp/ 全体を ignore しています。
    しかし tmp/ には issue_*_backup_*.md, issue_*_new_*.md, reviewer_feedback.md, edit_issue_*.md など、プロトコル運用上の中間ファイルが想定されています。これを LOCAL_MAIN_SCRATCH_ALLOW_V1 の broad safe-prefix にすると、生成物だけでなくレビュー本文、issue 本文バックアップ、作業指示系ファイルまで「safe scratch」として扱うことになります。

    tmp/ 全体ではなく、例えば以下のように用途別に狭めるべきです。

    safe_scratch_prefixes:
      - artifacts/local/
      - playwright-report/
      - test-results/
      - coverage/
      - .tmp/scratch/

    tmp/ を残すなら tmp/scratch/ のように専用 subtree に限定するべきです。

    技術・配布物ごとの実装品質レビュー

    Playwright の HTML reporter は、公式 docs 上もデフォルトで playwright-report に report を出力します。これは #974 の候補 prefix と整合します。(Playwright)
    Playwright Test の outputDir はデフォルトで <package.json-directory>/test-results で、テスト実行中に作られる file の出力先として使われます。これも候補 prefix と整合します。([Playwright]8)

    一方、artifacts/, coverage/, .cache/, .tmp/ はツール標準というより repo convention です。coverage.py の HTML report は source を annotated HTML として出すため、coverage 出力にはソース断片が含まれる可能性があります。([Coverage.py]9) したがって coverage/ を safe とするなら「commit されない」「PR artifact として配布しない」「secret scan 対象外にしない」などの運用条件も明記すべきです。

    また、#960 の review comment には、main working tree 上の untracked artifact、具体的には playwright-report/ や artifacts/ が lint/build の baseline 検証を汚染した、という実害が記録されています。これは #974 の動機として強い根拠ですが、同時に「artifact が eslint 等に拾われる」という事実でもあります。safe scratch にするだけでなく、toolchain 側でも ignore 対象にする必要があります。

    推奨する修正版 contract

    #974 の AC は次の水準まで具体化してください。

    LOCAL_MAIN_SCRATCH_ALLOW_V1:
      applies_to:
        - Write
        - Edit
        - MultiEdit
      optional_bash_support:
        status: phase_2
        requirement: only file-write mutations with statically extracted target paths
    
      local_main_context_required:
        - cwd_realpath == project_root_realpath
        - cwd_realpath is not inside expected_issue_worktree
        - cwd_realpath is not inside any linked issue worktree
        - current_branch == main_or_repo_default_branch
        - active issue may be resolved, but mutation target is local-main scratch only
    
      target_required:
        - target_realpath inside project_root_realpath
        - target_realpath outside expected_issue_worktree
        - target_realpath outside .git/**
        - target_realpath outside .claude/worktrees/**
        - normalized relpath starts with explicit safe_scratch_prefix
        - safe_scratch_prefix match uses path component boundary, not string prefix
        - no existing symlink component under safe root
        - parent directory exists and is not symlink
        - target, if exists, is not symlink
    
      git_required:
        - git ls-files --error-unmatch -- <rel> must return nonzero
        - git check-ignore -v -- <rel> must match repo-local .gitignore source
        - global excludes alone are insufficient
        - .git/info/exclude is insufficient unless explicitly allowed by contract
    
      sensitive_required:
        - deny .env*
        - deny *.pem, *.key, *.p12, *.pfx
        - deny *token*, *secret*, *credential*
        - deny .npmrc, .pypirc, .netrc
        - deny .ssh/**, .config/gh/**
        - deny Playwright auth storage state unless explicitly classified as disposable
    
      mutation_never_allowed_by_this_exception:
        - git add / commit / push / checkout / switch / reset / rebase / merge
        - gh pr/issue/api write operations
        - package manager install/add/remove/update/publish/version/link/unlink
        - unknown Bash with possible mutation

    git ls-files --error-unmatch は、path が index に存在しない場合に error を返すため、tracked/index 入り file の reject に使えます。([Git]10)
    git check-ignore は tracked files をデフォルトでは表示しないため、ls-files と check-ignore の両方が必要です。([Git]5)

    追加すべき adversarial tests

    最低限、以下の pytest を #974 の AC に含めるべきです。

    allow_local_main_write_to_repo_ignored_untracked_playwright_report
    allow_local_main_write_to_repo_ignored_untracked_test_results
    block_safe_prefix_not_in_repo_gitignore
    block_global_gitignore_only_match
    block_tracked_file_under_safe_prefix
    block_intent_to_add_or_index_present_under_safe_prefix
    block_artifacts_prefix_sibling_artifacts_evil
    block_artifacts_dotdot_readme
    block_symlink_safe_root_to_outside
    block_symlink_parent_component
    block_existing_target_symlink
    block_sensitive_dotenv_under_artifacts
    block_sensitive_npmrc_under_cache
    block_playwright_auth_storage_state_unless_explicitly_allowed
    block_write_when_cwd_inside_issue_worktree
    block_write_when_branch_is_issue_branch_not_main
    block_write_inside_dot_git_even_if_ignored
    block_write_inside_claude_worktrees_even_if_ignored
    block_bash_dynamic_destination_OUT_variable
    block_bash_package_manager_with_cache_arg
    block_git_add_force_ignored_scratch_file
    

    PR #971 の tests は、実 git repo と real issue worktree を作る behavioral harness で、__file__ anchor を使い、subprocess 経由で guard wrapper を叩く構成でした。この形式を #974 でも踏襲するべきです。

    実装方針

    おすすめは phase 分割です。

    Phase 1: Write/Edit/MultiEdit だけを対象にする。Bash 例外は入れない。
    Phase 2: PR #971 の write-target extraction を利用し、redirection/tee/sed/perl/interpreter one-liner のうち destination が静的に抽出できた file-write のみ許可する。dynamic destination は fail-closed のままにする。
    Phase 3: #963 が入った後、staged diff / git add -f ルートとの結合テストを追加する。

    実装は概ねこの形です。

    def is_local_main_scratch_allowed(tool_name, target_path, cwd, project_root, expected_worktree):
        if tool_name not in {"Write", "Edit", "MultiEdit"}:
            return False
    
        root = realpath(project_root)
        cwd_real = realpath(cwd)
        target = resolve_against_cwd(target_path, cwd_real)
    
        if cwd_real != root:
            return False
    
        if not current_branch_is_main_or_default(root):
            return False
    
        if expected_worktree and path_inside(realpath(expected_worktree), target):
            return False
    
        if not path_inside(root, target):
            return False
    
        rel = relpath(target, root)
    
        if rel_is_under(rel, ".git/") or rel_is_under(rel, ".claude/worktrees/"):
            return False
    
        if not rel_is_under_any_component_safe_prefix(rel, SAFE_SCRATCH_PREFIXES):
            return False
    
        if has_sensitive_name_or_component(rel):
            return False
    
        if has_symlink_component(root, rel):
            return False
    
        if git_ls_files_error_unmatch(root, rel) == 0:
            return False
    
        if not git_check_ignore_repo_local(root, rel):
            return False
    
        return True

    最終レビュー結論

    #974 は 実装してよいが、現状の draft AC では不足です。特に、現行 .gitignore と候補 prefix の不一致、global ignore 依存、local main 判定の曖昧さ、secret denylist 未定義、symlink/TOCTOU 未対策、#963 未導入時の git add -f ルートが問題です。

    修正後の merge 条件は次で固定してください。

    1. .gitignore に許可する scratch prefix を repo-local に追加する、または現行 .gitignore にある prefix だけを許可する。
    2. git check-ignore -v の source が repo-local .gitignore であることを検証する。
    3. git ls-files --error-unmatch で tracked/index 入りを reject する。
    4. cwd == project_root かつ branch が main/default のときだけ local main scratch と認める。
    5. safe-prefix は component boundary で照合し、artifacts_evil や artifacts/../README.md を block する。
    6. symlink component と sensitive path を fail-closed で block する。
    7. Bash 対応は phase 2 に分離し、git/gh/package-manager mutation は常に例外対象外にする。
    8. 実装: staging guard で git add -A と Allowed Paths 外 commit 混入を防ぐ #963 の staging guard が入るまで、git add -f / staged diff 混入を別 blocker として明記する。
  3. squne121 commented on Jun 17, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  4. squne121 commented on Jun 17, 2026

    @squne121
    OwnerAuthor

    CONTRACT_REVIEW_RESULT_V1

    status: go

    Contract Snapshot

    フィールド 値
    Issue #974
    Outcome worktree_scope_guard.py に LOCAL_MAIN_SCRATCH_ALLOW_V1 判定関数を実装し、local main context からの safe_scratch_prefix 配下への gitignored & untracked path への Write/Edit/MultiEdit のみ allow する
    Worktree .claude/worktrees/issue-974-local-main-scratch-allow
    Branch worktree-issue-974-local-main-scratch-allow
    body_sha256 sha256:f02fb5a89fd34567398cfec708f1dd0ca13ed71ba51dd47fea234f38780f8f1f

    Allowed Paths

    • .claude/hooks/worktree_scope_guard.py
    • .claude/hooks/tests/test_local_main_scratch_allow.py
    • .gitignore

    Acceptance Criteria

    AC1〜AC11(チェックボックス形式・決定論的 VC 付き)

    Verification Commands

    AC1〜AC11: uv run pytest .claude/hooks/tests/test_local_main_scratch_allow.py -v -k <filter> 形式

    checks

    check 結果
    template_compliance pass
    state_label pass(state/needs-human なし)
    allowed_paths_present pass
    vc_present pass
    stop_conditions_complete pass
    vc_preflight pass(AC1-AC11 all expected_baseline_fail/go, exit4)
    ac_verifiability pass
    product_spec_check not_applicable(hooks/guard 実装, docs/product 非対象)
    worktree_branch_collision pass(衝突なし)
    blockers resolved(#960 CLOSED / PR #971 MERGED。body に「マージ済み」と明記。native dependency 未登録は偽陽性として手動解決)
    next_action implement-issue へ handoff
    blocked_reasons なし

    VC preflight summary

    • expected_fail: 11(テストファイル未作成 exit4 = expected baseline fail)
    • skipped (runtime_only): 4
    • blocked: 0
    • human_judgment: 0

    Handoff

  5. squne121 commented on Jun 17, 2026

    @squne121
    OwnerAuthor

    実装完了

    PR #979(Draft)を作成しました。

    変更ファイル

    • .claude/hooks/worktree_scope_guard.py — LOCAL_MAIN_SCRATCH_ALLOW_V1 実装
    • .claude/hooks/tests/test_local_main_scratch_allow.py — AC11 behavioral harness(14 テスト)
    • .gitignore — safe_scratch_prefix 5 エントリ追加

    検証結果

    VC 結果
    uv run pytest .claude/hooks/tests/test_local_main_scratch_allow.py -v 14/14 pass
    uv run pytest .claude/hooks/tests/ --ignore=...test_local_main_scratch_allow.py 488/488 pass(既存退行なし)
    pnpm typecheck pass
    pnpm lint pass
    pnpm test 702/702 pass
    pnpm build pass

    設計上の主要な実装詳細

    • _is_repo_local_gitignore(): git check-ignore -v の出力ソースが相対パス(.gitignore)で返される場合は project_root を基準に解決(os.path.realpath(os.path.join(project_root, source_part)))
    • LOCAL_MAIN_SCRATCH_ALLOW_V1 チェックは _decide_write() 内で is_inside(expected, target) が False になった後に実行(worktree 内へのアクセスは従来通り allow、worktree 外への書き込みのみ scratch check を適用)
    • Phase 2(Bash write exception)は scope 外

    Allowed Paths 準拠

    allowed_paths_compliance: true

  6. added 2 commits that reference this issue on Jun 18, 2026
  7. squne121 commented on Jun 18, 2026

    @squne121
    OwnerAuthor

    post-merge-cleanup: 完了 (2026-06-18)

    • status: ok
    • 次アクション: なし
    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: post-merge-cleanup
      follow_up_issues: []
      note_only_observations: []

    実行内容:

    • branch worktree-issue-974-local-main-scratch-allow 削除済み
    • worktree .claude/worktrees/issue-974-local-main-scratch-allow 削除済み
    • main を origin/main に整合済み
    • リモート削除済み残留ブランチ 2 本 (issue-919, issue-936) も併せて削除済み
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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions