Skip to content

fix: context-mode execution-like tools の quarantine 方針と実効 deny を一致させ、CI テストを接続する #883

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#813"
goal_ref: "context-mode execution-like tools の quarantine を docs 方針と実効 permission deny で一致させ、AC10 テストを CI に接続する"
change_kind: fix

Parent Issue

#813

Parent Goal Ref

  • Goal: context-mode MCP を Claude Code に段階的導入し、大出力(Issue/PR/コメント/作業ログ)の read-only 圧縮・検索補助として安全に利用できる状態を確立する
  • Desired Destination: .claude/settings.json の permissions.deny が execution-like tools を完全に列挙し、docs/artifact と実効設定が一致した状態で CI の回帰防止テストが動作している

Current Validated Scope

  • .claude/settings.json:permissions.deny に mcp__context-mode__ctx_batch_execute / mcp__context-mode__ctx_execute_file / mcp__context-mode__ctx_execute / mcp__context-mode__ctx_fetch_and_index を完全列挙する
  • .github/workflows/ci.yml:python-test job に tests/context_mode/ を追加(ci_test_selection artifact 生成対象も同様)
  • .claude/artifacts/context-mode/cwd-comparison-result.json:全 case の git_rev_parse_head を 40 桁 SHA に更新
  • tests/context_mode/test_cwd_quarantine_artifact.py:test_head_sha_full_length および test_project_policy_matches_effective_settings テストを追加
  • docs/dev/agent-ops/context-mode-cwd-quarantine.md:policy 表記を実効 deny と整合させる
  • cwd-comparison-result.json の context-mode version 表現を version-provenance.json と矛盾しないよう整合させる

Remaining Parent Gaps

背景

PR #880 / Issue #826 で ctx_execute / ctx_batch_execute / ctx_execute_file の quarantine matrix を docs / artifact に記録した。

しかし最終マージ状態では .claude/settings.json の明示 deny は mcp__context-mode__ctx_execute と mcp__context-mode__ctx_fetch_and_index のみであり、mcp__context-mode__ctx_batch_execute / mcp__context-mode__ctx_execute_file は明示 deny されていない。

artifact/docs は両 tool を policy: deny と記録しているため、方針上の quarantine と実効 permission enforcement が混線している。また、AC10 の artifact schema test (tests/context_mode/test_cwd_quarantine_artifact.py) が CI の python-test job に接続されておらず、回帰防止ゲートとして機能していない。

さらに、cwd-comparison-result.json に記録された context-mode version 表現が version-provenance.json と矛盾する可能性があり、1.0.161 を残す場合は upstream bug reported version として field 名を分離する必要がある。

Current Objective

  1. .claude/settings.json の permissions.deny に mcp__context-mode__ctx_batch_execute、mcp__context-mode__ctx_execute_file、mcp__context-mode__ctx_execute、mcp__context-mode__ctx_fetch_and_index が存在し、permissions.allow / permissions.ask に同 tool の allow/ask が存在しない状態にする
  2. tests/context_mode/test_cwd_quarantine_artifact.py を CI の python-test job に接続し、ci_test_selection artifact 生成対象にも tests/context_mode/ を含める
  3. artifact の全 case の git_rev_parse_head を 40 桁 lowercase hex SHA に統一する
  4. artifact の project_policy.ctx_batch_execute / project_policy.ctx_execute_file を deny として整合させ、.claude/settings.json の実効 deny と一致させる
  5. test_cwd_quarantine_artifact.py に test_head_sha_full_length と test_project_policy_matches_effective_settings テストを追加する
  6. cwd-comparison-result.json の context-mode version 表現を version-provenance.json と矛盾しないよう整合させる(1.0.161 残存時は upstream bug reported version として field 名を分離)

Outcome

  • .claude/settings.json の permissions.deny に mcp__context-mode__ctx_execute、mcp__context-mode__ctx_batch_execute、mcp__context-mode__ctx_execute_file、mcp__context-mode__ctx_fetch_and_index が追加されており、permissions.allow / permissions.ask に同 tool が存在しない
  • tests/context_mode/test_cwd_quarantine_artifact.py が CI の python-test job で実行される(ci_test_selection artifact 生成対象を含む)
  • artifact の git_rev_parse_head が全 case で 40 桁 lowercase hex SHA になっている
  • artifact の project_policy.ctx_batch_execute / project_policy.ctx_execute_file が deny であり、.claude/settings.json の実効 deny と一致している
  • test_cwd_quarantine_artifact.py に test_head_sha_full_length と test_project_policy_matches_effective_settings が存在する
  • cwd-comparison-result.json の context-mode version 表現が version-provenance.json と矛盾しない

In Scope

  • .claude/settings.json に mcp__context-mode__ctx_batch_execute と mcp__context-mode__ctx_execute_file を deny 追加(mcp__context-mode__ctx_execute / mcp__context-mode__ctx_fetch_and_index は既存)
  • .github/workflows/ci.yml の python-test job に tests/context_mode/ を追加、および ci_test_selection artifact 生成対象に tests/context_mode/ を含める
  • .claude/artifacts/context-mode/cwd-comparison-result.json の git_rev_parse_head を全 case 40 桁 SHA に更新
  • artifact / docs の policy 表記を実効 deny と整合させる
  • cwd-comparison-result.json の version 表現を version-provenance.json と整合させる(1.0.161 残存時は field 名分離)

Out of Scope

  • ctx_execute quarantine の解除
  • upstream context-mode の修正
  • context-mode のその他 tool の評価

Acceptance Criteria

  • AC1: .claude/settings.json の permissions.deny に
    mcp__context-mode__ctx_execute,
    mcp__context-mode__ctx_batch_execute,
    mcp__context-mode__ctx_execute_file,
    mcp__context-mode__ctx_fetch_and_index
    が存在し、permissions.allow / permissions.ask に同 tool の allow/ask が存在しない

  • AC2: CI の python-test job で uv run --locked pytest tests/context_mode/ -q が実行される

  • AC3: CI の ci_test_selection/v1 artifact 生成対象にも tests/context_mode/ が含まれる

  • AC4: artifact の cases.*.bash_evidence.git_rev_parse_head は、bash_evidence.status がない全 case で 40 桁 lowercase hex SHA である

  • AC5: artifact の project_policy.ctx_batch_execute / project_policy.ctx_execute_file は deny であり、かつ .claude/settings.json の実効 deny と一致している

  • AC6: test_cwd_quarantine_artifact.py に test_head_sha_full_length と test_project_policy_matches_effective_settings が存在する

  • AC7: cwd-comparison-result.json の context-mode version 表現が version-provenance.json と矛盾しない。1.0.161 を残す場合は upstream bug reported version として field 名を分離する

Verification Commands

# AC1
$ rg -n "mcp__context-mode__ctx_batch_execute|mcp__context-mode__ctx_execute_file|mcp__context-mode__ctx_execute|mcp__context-mode__ctx_fetch_and_index" .claude/settings.json

# AC2
$ rg -n "tests/context_mode" .github/workflows/ci.yml

# AC3
$ rg -n "ci_test_selection" .github/workflows/ci.yml

# AC4
$ uv run --locked pytest tests/context_mode/test_cwd_quarantine_artifact.py::test_head_sha_full_length -v

# AC5
$ uv run --locked pytest tests/context_mode/test_cwd_quarantine_artifact.py::test_project_policy_matches_effective_settings -v

# AC6
$ rg -q "test_head_sha_full_length|test_project_policy_matches_effective_settings" tests/context_mode/test_cwd_quarantine_artifact.py

# AC7
$ uv run python3 -c "import json; a=json.load(open('.claude/artifacts/context-mode/cwd-comparison-result.json')); v=a.get('context_mode_version') or a.get('upstream_756_reported_context_mode_version'); assert v, 'no version field found'; print(v)"

Allowed Paths

  • .claude/settings.json
  • .claude/artifacts/context-mode/**
  • tests/context_mode/**
  • .github/workflows/ci.yml
  • docs/dev/agent-ops/context-mode-cwd-quarantine.md

Runtime Verification Applicability

  • decision: not_applicable
  • reason: 全 AC の検証は rg による設定ファイルの grep と pytest による決定論的ユニットテストのみで完結する。プロセス起動・通信・実 MCP 接続は不要。

Stop Conditions

  • .claude/settings.json を ctx_execute allow に変更する必要が出た場合
  • ctx_batch_execute / ctx_execute_file を routine-use に昇格させる変更が発生した場合
  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合
  • 後続 Phase / 別スコープへの波及が判明した場合

Required Skills

  • Python / pytest(test_cwd_quarantine_artifact.py 拡張実装)
  • GitHub Actions / YAML(ci.yml の python-test job 更新)
  • JSON(cwd-comparison-result.json artifact の 40 桁 SHA 更新・version 表現整合)

Delivery Rule

Handoff Contract

Current Objective

上記「Current Objective」を参照。

Bounded Current Context

  • PR docs: record context-mode cwd quarantine evidence for issue 826 #880 (マージ済み): 3 ファイル追加、quarantine matrix docs 化、AC10 テスト追加
  • .claude/settings.json 現状: mcp__context-mode__ctx_execute と mcp__context-mode__ctx_fetch_and_index のみ明示 deny
  • tests/context_mode/test_cwd_quarantine_artifact.py: 22 tests、CI 未接続

Open Questions

  • CI python-test job の実行パターン(tests/context_mode/ を glob で追加するか、個別 step を追加するか)

Next Action

  1. .claude/settings.json に mcp__context-mode__ctx_batch_execute と mcp__context-mode__ctx_execute_file を deny 追加
  2. .github/workflows/ci.yml の python-test に tests/context_mode/ を追加(ci_test_selection artifact 対象も更新)
  3. artifact の SHA を 40 桁に更新
  4. テストに test_head_sha_full_length と test_project_policy_matches_effective_settings を追加
  5. cwd-comparison-result.json の version 表現を整合させる
  6. VC を実行して PR 作成

Artifact Refs

  • .claude/artifacts/context-mode/cwd-comparison-result.json
  • tests/context_mode/test_cwd_quarantine_artifact.py
  • .github/workflows/ci.yml

Activity

  1. squne121 commented on Jun 13, 2026

    @squne121
    OwnerAuthor

    敵対的レビュー結論: REQUEST_CHANGES

    #883 の方向性は正しいです。現状、.claude/settings.json の実効 deny は mcp__context-mode__ctx_execute と mcp__context-mode__ctx_fetch_and_index だけで、ctx_batch_execute / ctx_execute_file は明示 deny されていません。にもかかわらず artifact/docs 側では両者を deny と記録しており、#883 が指摘する「方針と実効 enforcement の不一致」は事実です。

    ただし、#883 のまま実装すると 「見かけ上は直ったが、evidence integrity と CI evidence がまだ弱い」 状態になります。Issue 契約を少し強化してから実装すべきです。

    主要な指摘

    1. AC3 が本文目的より弱い

    #883 の Current Objective は「artifact の git_rev_parse_head を全 case で 40 桁 SHA に統一」と言っていますが、AC3 は main_checkout.bash_evidence.git_rev_parse_head だけを対象にしています。現 artifact では main_checkout が 1b8f71b の短縮 SHA で、linked/nested は 40 桁です。

    修正案: AC3 を 全 case の bash_evidence.git_rev_parse_head が 40 桁 lowercase hex に変更してください。main_checkout だけを直すと、将来別 case が短縮 SHA に退行しても CI が通ります。

    2. 既存テストは「短縮 SHA」を落とせない

    現在の tests/context_mode/test_cwd_quarantine_artifact.py は git_rev_parse_head が None/null/pending/unknown でないことしか検査していません。40 桁 SHA の regex 検査はありません。

    追加すべきテスト名は #883 の AC5 にある test_head_sha_full_length でもよいですが、実装は main_checkout 固定ではなく、artifact["cases"] を走査する形にしてください。

    SHA40 = re.compile(r"^[0-9a-f]{40}$")
    
    def test_head_sha_full_length(artifact):
        bad = {}
        for case_name, case in artifact["cases"].items():
            bash = case.get("bash_evidence", {})
            if "status" in bash:
                continue
            sha = bash.get("git_rev_parse_head")
            if not isinstance(sha, str) or not SHA40.fullmatch(sha):
                bad[case_name] = sha
        assert not bad

    3. project_policy: deny だけでは不十分。settings との parity test が必要

    artifact は ctx_batch_execute / ctx_execute_file を deny と書いていますが、同じ policy_source_note 内で「settings 上の明示 deny に入っていない」と認めています。これは evidence として矛盾しています。

    Claude Code の permission 設定は allow / ask / deny を持ち、tool 名や glob を使って制御でき、deny が優先評価されます。したがって #883 では「artifact に deny と書く」だけでなく、.claude/settings.json の permissions.deny に exact tool name があることをテストで検証すべきです。([Claude API Docs]1)

    追加推奨:

    SETTINGS_PATH = Path(".claude/settings.json")
    
    EXECUTION_LIKE_DENY_TOOLS = {
        "ctx_execute": "mcp__context-mode__ctx_execute",
        "ctx_batch_execute": "mcp__context-mode__ctx_batch_execute",
        "ctx_execute_file": "mcp__context-mode__ctx_execute_file",
    }
    
    def test_execution_like_tools_explicitly_denied_in_settings():
        settings = json.loads(SETTINGS_PATH.read_text())
        deny = set(settings["permissions"]["deny"])
        missing = sorted(set(EXECUTION_LIKE_DENY_TOOLS.values()) - deny)
        assert not missing
    
    def test_project_policy_matches_effective_settings(artifact):
        settings = json.loads(SETTINGS_PATH.read_text())
        deny = set(settings["permissions"]["deny"])
        policy = artifact["project_policy"]
    
        for policy_key, tool_name in EXECUTION_LIKE_DENY_TOOLS.items():
            assert policy[policy_key] == "deny"
            assert tool_name in deny
    
        assert "明示 deny に入っていない" not in policy.get("policy_source_note", "")

    4. CI 接続は pytest tests/context_mode/ だけでは足りない可能性が高い

    現 CI の python-test job には tests/context_mode/ が入っていません。多数の .claude/skills/** や hook/schema テストは実行されていますが、context-mode テストは未接続です。

    さらに、CI の ci_test_selection artifact 生成部分の pytest_args にも tests/context_mode/ が含まれていません。ここを更新しないと、「CI で何を選んだか」の machine-readable evidence が実態とズレます。

    修正案:

    - run: uv run --locked pytest tests/context_mode/ -q

    に加えて、Generate ci_test_selection/v1 artifact の pytest_args にも:

    "tests/context_mode/",

    を追加してください。pytest はディレクトリ指定で配下のテストを収集・実行できます。([pytestドキュメント]2) uv run --locked は lockfile 更新を禁止し、lockfile が古い場合に失敗するため CI 向きです。([Astral Docs]3)

    5. context_mode_version の artifact drift を同時に潰すべき

    cwd-comparison-result.json は context_mode_version: "1.0.161" ですが、version provenance artifact は installed version / release tag / plugin manifest version を 1.0.162 と記録しています。 context-mode 側でも v1.0.162 が最新リリースとして示されています。([GitHub]4)

    これは #883 の主目的ではありませんが、同じ artifact を更新するなら放置しない方がよいです。選択肢は二つです。

    1. context_mode_version を 1.0.162 に更新する。
    2. 1.0.161 は upstream feat-storage-add-snapshot-schema-migration-issue-736 #756 の再現バージョンとして残し、field 名を upstream_756_reported_context_mode_version に変え、別途 installed_context_mode_version: "1.0.162" を追加する。

    後者の方が証跡として正確です。

    6. execution-like tools の deny は妥当。allow/ask へ広げてはいけない

    context-mode は ctx_batch_execute、ctx_execute、ctx_execute_file を sandbox tools として提供しています。ctx_batch_execute は複数コマンド、ctx_execute_file は script file 実行に関係するため、ctx_execute と同じ execution-like surface と見なすべきです。([GitHub]4)

    upstream #756 は ctx_execute が session の worktree ではなく MCP server 側の process cwd / main checkout で実行される silent wrong-directory bug です。read-only の git status や rg でも wrong tree を読むとレビュー判断が壊れます。([GitHub]5) したがって #883 の Stop Conditions にある通り、ctx_batch_execute / ctx_execute_file を routine-use に昇格する変更は拒否でよいです。

    7. 過去の fail-open 系 upstream issue を考えると、grep VC だけでは弱い

    context-mode には過去に permissions.deny が silent fail-open した issue #558、ctx_index が deny-policy を迂回して任意ファイルを FTS5 index に読めた issue #442 がありました。どちらも closed ですが、「設定を書いた」だけでは security evidence として弱いという設計上の教訓は残ります。([GitHub]6)

    #883 では runtime negative test までは難しいとしても、最低限 static parity test を追加してください。つまり、settings.json、artifact の project_policy、docs matrix が同じ tool set を同じ policy で表現していることをテスト化します。

    #883 に追記すべき Acceptance Criteria

    差し替え案です。

    - [ ] AC1: `.claude/settings.json` の `permissions.deny` に
      `mcp__context-mode__ctx_execute`,
      `mcp__context-mode__ctx_batch_execute`,
      `mcp__context-mode__ctx_execute_file`,
      `mcp__context-mode__ctx_fetch_and_index`
      が存在し、`permissions.allow` / `permissions.ask` に同 tool の allow/ask が存在しない
    
    - [ ] AC2: CI の `python-test` job で `uv run --locked pytest tests/context_mode/ -q` が実行される
    
    - [ ] AC3: CI の `ci_test_selection/v1` artifact 生成対象にも `tests/context_mode/` が含まれる
    
    - [ ] AC4: artifact の `cases.*.bash_evidence.git_rev_parse_head` は、`bash_evidence.status` がない全 case で 40 桁 lowercase hex SHA である
    
    - [ ] AC5: artifact の `project_policy.ctx_batch_execute` / `project_policy.ctx_execute_file` は `deny` であり、かつ `.claude/settings.json` の実効 deny と一致している
    
    - [ ] AC6: `test_cwd_quarantine_artifact.py` に `test_head_sha_full_length` と `test_project_policy_matches_effective_settings` が存在する
    
    - [ ] AC7: `cwd-comparison-result.json` の context-mode version 表現が `version-provenance.json` と矛盾しない。1.0.161 を残す場合は upstream bug reported version として field 名を分離する

    実装指示としての最終判断

    #883 は 実装してよいが、Issue 契約を強化してから が妥当です。最小修正だけなら「2 tool deny 追加 + CI にテスト追加 + SHA 修正」で終わりますが、それだとまた artifact / CI evidence の drift が残ります。

    特に優先度が高いのはこの 4 点です。

    1. .claude/settings.json に mcp__context-mode__ctx_batch_execute / mcp__context-mode__ctx_execute_file を exact deny 追加。
    2. tests/context_mode/ を python-test job と ci_test_selection artifact 生成対象の両方に追加。
    3. git_rev_parse_head の 40 桁検査を全 case に拡張。
    4. artifact の policy_source_note から「settings 上の明示 deny に入っていない」という古い説明を削除し、実効 settings deny と一致させる。

    この形なら、#826/PR #880 の follow-up として #883 は十分に高品質化できます。

  2. squne121 commented on Jun 13, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Human Escalation Required

    The loop has terminated and requires human review. Cause: human judgment required

    Blockers

    "PLANNER_FAIL_CLOSED: missing_required_section"
    
    "Issue #883 は implementation テンプレートの必須セクションが欠けている: Parent Goal Ref / Current Validated Scope / Remaining Parent Gaps / Required Skills"
    
    "preflight exit_code=2 → NEXT_ACTION: human_judgment_required"
    
  3. squne121 commented on Jun 13, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  4. squne121 commented on Jun 13, 2026

    @squne121
    OwnerAuthor

    CONTRACT_REVIEW_RESULT_V1

    schema: CONTRACT_REVIEW_RESULT_V1
    issue_number: 883
    repo: squne121/loop-protocol
    status: go
    generated_at: "2026-06-14T00:00:00Z"

    checks

    template_compliance: pass
    state_label: pass
    allowed_paths_present: pass
    vc_present: pass
    stop_conditions_complete: pass
    product_spec_check:
      applicability: not_applicable
      decision: pass
    worktree_branch_collision: pass
    blockers: pass
    vc_preflight: go_with_annotations
    ac_verifiability: pass
    next_action: implement
    blocked_reasons: []

    VC Preflight 分類

    AC exit classification decision 根拠
    AC1 0 unexpected_pass go (annotated) ctx_execute / ctx_fetch_and_index が既に deny 済みのため OR-match が partial hit。実装後に 4 全件が deny に揃う。
    AC2 1 expected_fail go tests/context_mode が ci.yml に未追加。正常な baseline fail。
    AC3 0 unexpected_pass go (annotated) ci_test_selection キーワードが他テスト向けに既存。VC は当該 step への tests/context_mode/ 追加を区別できない。実装後に追加される。
    AC4 4 human_judgment go pytest exit 4 = test 関数未存在 (no tests collected)。baseline 未実装状態として期待される。
    AC5 4 human_judgment go AC4 同様。
    AC6 null broad_search_path_unbounded go (false positive) search path が tests/context_mode/test_cwd_quarantine_artifact.py と specific file を指定。preflight の broad 判定は false positive。
    AC7 null command_not_allowed go (vc_format_note) uv run python3 -c が allowlist 外。AC 実装意図は明確、format 非準拠のみ。

    Worktree / Branch

    worktree: .claude/worktrees/issue-883-ctx-quarantine-ci-fix
    branch: worktree-issue-883-ctx-quarantine-ci-fix
    collision: none

    contract_snapshot

    outcome: |
      .claude/settings.json の permissions.deny に全 4 execution-like tools を追加し、
      tests/context_mode/ を CI python-test job と ci_test_selection artifact に接続し、
      artifact の git_rev_parse_head を全 case 40 桁 SHA に統一し、
      2 つの新テスト (test_head_sha_full_length / test_project_policy_matches_effective_settings) を追加する。
    
    allowed_paths:
      - .claude/settings.json
      - .claude/artifacts/context-mode/**
      - tests/context_mode/**
      - .github/workflows/ci.yml
      - docs/dev/agent-ops/context-mode-cwd-quarantine.md
    
    body_sha256: "sha256:d803ca3ebc88b9ca34f1dc8d9c19e66a1b56b50bdd7d43934363da5566cb7f1d"
  5. squne121 commented on Jun 13, 2026

    @squne121
    OwnerAuthor

    IMPLEMENTATION_RESULT

    PR: #887 (Draft)
    Branch: worktree-issue-883-ctx-quarantine-ci-fix
    Commit: 2db55e4

    AC 検証

    AC 結果 備考
    AC1 PASS settings.json deny に 4 ツール全件確認
    AC2 PASS CI python-test job に pytest tests/context_mode/ -q 追加
    AC3 PASS ci_test_selection/v1 pytest_args に tests/context_mode/ 追加
    AC4 PASS test_head_sha_full_length PASS(全 case 40 桁 SHA 確認)
    AC5 PASS test_project_policy_matches_effective_settings PASS
    AC6 PASS 両テスト実装済み・検索確認済み
    AC7 PASS context_mode_version: "1.0.162"(provenance と一致)、旧 1.0.161 は upstream_756_reported_context_mode_version に分離

    品質ゲート

    • pnpm typecheck: PASS
    • pnpm lint: PASS
    • pnpm test: 598 passed
    • pnpm build: PASS
    • uv run --locked pytest tests/context_mode/ -q: 96 passed(新規 2 テスト含む)

    変更ファイル(Allowed Paths 内のみ)

    • .claude/settings.json: ctx_batch_execute / ctx_execute_file を deny 追加
    • .claude/artifacts/context-mode/cwd-comparison-result.json: SHA 40 桁化・version 整合・policy_source_note 更新
    • .github/workflows/ci.yml: tests/context_mode/ を python-test job と ci_test_selection に接続
    • tests/context_mode/test_cwd_quarantine_artifact.py: TestAC883 クラスに 2 テスト追加
  6. added 2 commits that reference this issue on Jun 13, 2026
  7. added a commit that references this issue on Jun 14, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions