Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#813"
goal_ref: "context-mode MCP を Claude Code に段階的導入し、大出力を扱う read-only 調査補助として運用する"
change_kind: workflowParent Issue
Parent Goal Ref
context-mode MCP を Claude Code に段階的導入し、大出力を扱う read-only 調査補助として運用する(#813)。ctx_index / ctx_search を routine-use に進める前に、secret 漏洩経路を negative test で封鎖することが前提条件となる。
Current Validated Scope
- feat: context-mode を実験用 profile に導入し version / doctor / tools / permission を artifact 化する (#824) #856 で context-mode は project-shared / commit-tracked 形式で有効化済み
registered-tools.jsonにctx_index/ctx_searchがregistered_pending_child_issue_825として記録済みctx_execute/ctx_fetch_and_indexは別 child 完了まで deny 維持- 実装: context-mode deny rule を secret / token / config negative test 付きで fail-closed 化する #825 は ctx_index / ctx_search を routine-use に進めるための安全ゲートである
Remaining Parent Gaps
- 調査: context-mode ctx_execute の worktree cwd 安全性を検証し quarantine 方針を固定する #826: ctx_execute quarantine(別 child)
- 実装: context-mode ctx_fetch_and_index を CTX_FETCH_STRICT=1 と network negative test で隔離する #827: ctx_fetch_and_index + CTX_FETCH_STRICT=1 network negative test(別 child)
- 実装: context-mode の persistence / purge / ELv2 notice policy を docs 化する #828: persistence / purge / ELv2 notice policy(別 child)
Required Skills
- uv(Python テストランナー)
- pytest(integration test harness)
Current Objective
context-mode の read/index/search 経路で .env / SSH / gh / Claude config / environment token が漏れないことを、設定レビューではなく negative test で固定する。
Background
upstream context-mode には過去に ctx_index が deny pattern を迂回して file content を FTS index に取り込み、ctx_search で引ける問題があった(upstream #442)。また permissions.deny が silent fail-open になる問題も報告されている。closed 済みであっても、loop-protocol 側では regression test として固定する。ctx_execute は upstream #756 の open bug(MCP server の process cwd で動作し worktree に従わない)があり、read-only command でも wrong-tree になる。
Outcome
.claude/settings.json に context-mode 用 deny rule が入り、ctx_index -> ctx_search 経路・direct read 経路の negative test が artifact として残る。deny rule を意図的に壊す mutation test が pass することで、テストハーネス自体の有効性を担保する。
In Scope
.claude/settings.jsonの context-mode deny rule 整備(実 callable tool 名と一致する検証付き).env/*.env*/ synthetic HOME 配下.ssh/**/.config/gh/**/.claude/**の deny- repo 内 fixture secret に対する
ctx_index -> ctx_searchnegative test(positive control 付き) - token dump コマンドの static policy deny 検証(実コマンド実行なし)
- deny rule mutation test(fail-closed 確認)
- evidence artifact 作成(schema
context_mode_deny_negative_test_v1) - CONTEXT_MODE_DIR の isolated cleanup 検証
Out of Scope
- 実 secret の出力・保存
ctx_executeの許可(upstream feat-storage-add-snapshot-schema-migration-issue-736 #756 open bug により対象外)- Codex CLI hooks
- production / CI secret へのアクセス
ctx_fetch_and_indexテスト(実装: context-mode ctx_fetch_and_index を CTX_FETCH_STRICT=1 と network negative test で隔離する #827 の責務)- persistence / purge policy(実装: context-mode の persistence / purge / ELv2 notice policy を docs 化する #828 の責務)
Acceptance Criteria
- AC1:
.claude/settings.jsonを JSON として parse し、context-mode の実 callable tool 名と一致する deny entry が検証される。rg文字列一致だけでは不可 - AC2:
ctx_index -> ctx_searchで positive control(LP_CONTEXT_MODE_PUBLIC_CANARY)が成功し、同じ harness で.env/*.env*fixture の secret canary が検索不能である - AC3: synthetic HOME 配下の
.ssh/**/.config/gh/**/.claude/**fixture が direct read / index / search 経由で漏れない。実 HOME は使用しない - AC4:
gh auth token/printenv/env等の token dump コマンドが static policy で deny される。実コマンドは実行しない。runtime surrogate を使う場合は isolated env の fake token のみ - AC5: deny rule を temp settings 上で意図的に壊す mutation test が fail し、現行 settings では pass する
- AC6:
.claude/artifacts/context-mode/deny-negative-test.jsonが schemacontext_mode_deny_negative_test_v1を満たし、raw secret marker / token-like value / unredacted home path を含まない - AC7: test 後に
CONTEXT_MODE_DIRの isolated cleanup または purge が検証され、fixture canary が FTS index に残っていない
Verification Commands
# AC1
# AC2
# AC3
# AC4
# AC5
# AC6
# AC7
$ uv run pytest tests/context_mode/test_deny_secrets.py -vAllowed Paths
.claude/settings.json.claude/artifacts/context-mode/**scripts/test_context_mode_permissions.pytests/context_mode/**tests/fixtures/context-mode/**docs/dev/agent-ops/**
Runtime Verification Applicability
decision: immediate
reason: pytest による静的 JSON parse 検証・fixture を使った negative test・mutation test がすべて本 Issue 実装範囲内で成立する。context-mode plugin の実起動は不要(synthetic HOME・isolated CONTEXT_MODE_DIR 使用)
applicable_acs:
- AC2
- AC3
- AC5
- AC6
- AC7
execution_environment:
cli_tools:
- uv
- pytest
auth_required: false
network_required: false
notes: synthetic HOME と isolated CONTEXT_MODE_DIR を使用。実 context-mode MCP サーバーの起動は不要。fake token のみ使用
skip_conditions:
- context-mode plugin not installed (exit 77)
fallback_policy:
fallback_success_is_pass: false
notes: skip condition を満たさない場合は FAIL として扱う
artifact_requirements:
- ".claude/artifacts/context-mode/deny-negative-test.json (schema: context_mode_deny_negative_test_v1)"Stop Conditions
- 実 secret を test に使う必要が出た場合
- deny rule が context-mode plugin 自体の起動を壊す場合
~/.claude/**deny が plugin storage / settings と衝突し、設計判断が必要になった場合- 実装: Claude / Codex hook の stdout policy と compaction 時 loop state 保存・復元 hint を fixture 検証付きで整備する #797 の hook stdout policy と conflict する場合
- context-mode upstream のバージョン更新により deny/allow メカニズムが変更され、現行 deny rule の実効性が不明になった場合
registered-tools.jsonと.claude/settings.jsonの tool 名が乖離し、deny rule と実 callable tool 名の対応が確認できなくなった場合
Delivery Rule
- 1 Issue = 1 PR
- Draft PR 既定
- child 1 完了後に着手する
Safety Claim Matrix
| Claim | 実装予定 | 対象外 | Evidence | Follow-up |
|---|---|---|---|---|
| ctx_index -> ctx_search で fixture secret が漏れない | yes | 実 HOME / 実 secrets | deny-negative-test.json | #828 purge policy |
| token dump command を実行せず deny policy を検証 | yes | 実 gh auth token | test_context_mode_permissions.py | #826 ctx_execute quarantine |
| artifact に token-like value が残らない | yes | GitHub secret scanning 設定 | artifact schema test | none |
Activity
fix: PR #856 レビュー指摘(Blocker 1-6)を修正する (#824)
feat: context-mode を実験用 profile に導入し version / doctor / tools / permi…
squne121 commentedon Jun 13, 2026
判定: REQUEST_CHANGES
#825 の目的は妥当です。特に、
ctx_index -> ctx_search経路で.env/ SSH / gh / Claude config / token 系情報が漏れないことを「設定レビュー」ではなく negative test で固定する、という方向は正しいです。#825 自体には現時点でコメントはありません。ただし、現行の Issue 契約のままだと fail-closed ではなく “deny rule を書いたつもり” で pass する危険があります。親 #813 は context-mode をセキュリティ境界として信頼しない前提で、
ctx_execute/ctx_fetch_and_indexは別 child 完了まで deny、ctx_index/ctx_searchも negative test 完了まで許可候補に留めています。関連PRとしては #856 が重要です。#856 で context-mode は project-shared / commit-tracked な形で有効化され、
registered-tools.jsonにはctx_index/ctx_searchがregistered_pending_child_issue_825として記録されています。つまり #825 は、単なる追加テストではなく ctx_index / ctx_search を routine-use に進めるかどうかの安全ゲートです。Blocker 1: AC1 の
rg検証は fail-closed ではない現行 VC は次です。
rg -n "ctx_index|ctx_search|ctx_execute|\\.env|\\.ssh|\\.config/gh|\\.claude" .claude/settings.jsonこれは「文字列がある」ことしか見ません。deny と allow の区別、コメント内の文字列、誤った tool 名、実際の callable tool 名との不一致を検出できません。#825 の AC1/AC5 の安全主張に対しては不十分です。
修正方針:
.claude/settings.jsonを JSON として parse し、最低限これを検証してください。#856 では
actual_callable_tool_names/deny_name_matches_callableを artifact に追加しているので、#825 はこれを前提に構造化検証へ寄せるべきです。Blocker 2:
ctx_index -> ctx_searchの positive control がない#825 は
ctx_index -> ctx_searchの negative test を要求していますが、現契約では「検索できなかった」の理由が deny 成功なのか、テストハーネスが壊れているのか、index が動いていないのかを区別できません。context-mode のctx_indexは FTS5 に chunk を保存し、ctx_searchがその実コンテンツ片を返す設計です。([GitHub]1)上流 #442 はまさにこの経路の問題で、
ctx_indexが path validation なしにファイルを FTS5 DB へ取り込み、その後ctx_searchで.ssh/id_rsaや.env相当の内容を返せる、という報告でした。([GitHub]2)修正方針: negative test には必ず positive control を入れてください。
positive control なしの「検索不能」は安全証明になりません。
Blocker 3:
~/.claude/**deny は context-mode 自身の storage と衝突し得る#825 は
~/.claude/**を deny 対象にしていますが、context-mode はCONTEXT_MODE_DIRを使い、Claude adapter では~/.claude/context-mode系の storage を使う前提があります。README でも indexed content は<root>/content、sessions/stats は<root>/sessionsと説明されています。([GitHub]1)#825 の Stop Condition にはこの衝突が書かれていますが、現状では「衝突したら止まる」だけで、テスト設計がありません。
修正方針: 実
HOMEを触らず、pytest のtmp_pathで synthetic HOME を作ってください。テスト時は次を固定します。
これにより、実
~/.ssh/~/.config/gh/~/.claudeを一切参照せず、context-mode storage との衝突も再現可能になります。Blocker 4: AC4「token dump command deny」は
ctx_executeout-of-scope と矛盾している#825 は AC4 で token dump command の deny を要求していますが、Out of Scope で
ctx_executeの許可を明示的に除外しています。これは危険な曖昧さです。
gh auth tokenやprintenvを実行して deny されたことを確認しようとすると、テスト自体が secret surface に触ります。さらにctx_executeは upstream #756 で、worktree ではなく MCP server の process cwd / main checkout 側で動く open bug が報告されており、read-only command でも silent wrong-tree になります。([GitHub]3)修正方針: AC4 は runtime 実行ではなく、まず policy-level / synthetic command-level に限定してください。
Blocker 5: Artifact が「ファイル存在」だけでは証跡にならない
現 AC6 は
deny-negative-test.jsonの存在確認だけです。これでは何を試したのか、どの surface で deny されたのか、search hit が 0 だったのか、redaction 済みか、mutation test が効いたのかが分かりません。必須 artifact schema 案:
{ "schema": "context_mode_deny_negative_test_v1", "issue": "#825", "status": "pass", "context_mode_version": "1.0.162", "surfaces": { "ctx_index_to_ctx_search": { "positive_control_passed": true, "negative_controls": [ { "fixture_kind": "env_file", "path_redacted": "<TMP_HOME>/.env", "expected": "deny_or_unsearchable", "actual": "unsearchable", "search_hit_count": 0, "raw_marker_persisted": false } ] }, "direct_read": { "negative_controls_passed": true }, "command_policy": { "real_secret_commands_executed": false, "static_policy_passed": true } }, "mutation_test": { "deny_removed_should_fail": true, "observed_failure": true }, "redaction": { "home_paths_redacted": true, "token_like_values_absent": true, "raw_fixture_markers_absent": true }, "purge": { "context_mode_dir_isolated": true, "purge_or_tmpdir_cleanup_verified": true } }GitHub secret scanning は repository history、issues、PR comments なども対象に credentials を検出します。fixture は本物に見える provider token 形式を避け、
FAKE_prefix と独自 canary にすべきです。([GitHub Docs]4)Blocker 6:
ctx_fetch_and_index/ persistence / purge との境界が弱い#825 の対象は deny rule ですが、実際には FTS5 index へ一度入った情報の purge まで安全性に含まれます。context-mode は
ctx_purgeで indexed content を削除できると説明しています。([GitHub]1)#827 は
ctx_fetch_and_indexとCTX_FETCH_STRICT=1の network negative test、#828 は persistence / purge / ELv2 notice policy を扱う sibling issue です。#825 は fetch をテスト対象に混ぜず、ただし index 汚染時の cleanup proof は持つべきです。修正方針: #825 の artifact に
CONTEXT_MODE_DIRが temp dir であること、またはctx_purge/ tmpdir cleanup 後に canary が検索不能であることを記録してください。Blocker 7: テスト配置が既存 convention とずれている
#825 の VC は
tests/fixtures/context-mode/test_deny_secrets.pyを実行していますが、fixture directory に test 本体を置くのは役割が混ざります。#856 はtests/context_mode/test_artifact_schema.pyを使っています。修正方針: Allowed Paths を次のように分けるのがよいです。
Issue の Allowed Paths に
tests/context_mode/**を追加してください。現在の Allowed Paths では、#824 で作った convention を継承しにくいです。推奨する #825 契約修正
そのまま Issue 本文へ入れるなら、Acceptance Criteria は以下に置き換えるのが妥当です。
Verification Commands はこうした方がよいです。
Allowed Paths は以下へ修正してください。
実装品質の要求水準
#825 は「セキュリティ境界の自己申告禁止」Issue です。したがって、PR 本文には Safety Claim Matrix を必須にしてください。#856 でも
.claude/settings.jsonの deny 追加は safety-sensitive として扱われています。最低限、PR 本文にこれを要求してください。
最終判断
現 #825 は、方向性は正しいですが、このまま実装に渡すと 「deny rule を書いた」「artifact ファイルを置いた」だけで pass する余地があります。特に
rgVC、positive control 不在、実 HOME に触れ得る設計、ctx_executeout-of-scope と AC4 の矛盾は merge-blocking と見ます。先に Issue body を上記のように修正し、#825 を ctx_index / ctx_search の routine-use 解禁ゲートとして扱うべきです。
squne121 commentedon Jun 13, 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 13, 2026
CONTRACT_REVIEW_RESULT_V1
squne121 commentedon Jun 13, 2026
implement-issue: 実装完了 (2026-06-13T07:05:28Z)
.claude/worktrees/issue-825-context-mode-deny-rule-secret-token-confworktree-issue-825-context-mode-deny-rule-secret-token-confsqune121 commentedon Jun 13, 2026
impl-review-loop: 完了 (2026-06-13T07:50:00Z)
fix(#825): address 7 blockers from adversarial review of context-mode…
squne121 commentedon Jun 13, 2026
impl-review-loop iteration 2 完了 (2026-06-13)
対応済み adversarial review blockers
VC 結果
uv run pytest tests/context_mode/test_deny_secrets.py -v: 46/46 PASStest: context-mode deny rule secret token negative test (#866)
squne121 commentedon Jun 13, 2026
post-merge-cleanup: 完了 (2026-06-13T10:35:00Z)
手動 cleanup コマンド
# worktree 内の pre-existing 削除を確認後、force 削除 git worktree remove --force .claude/worktrees/issue-825-context-mode-deny-rule-secret-token-conf git branch -d worktree-issue-825-context-mode-deny-rule-secret-token-conftests/fixtures/agent-session-manifest/temp-invalid-no-markers.mdの unstaged deletion が worktree に残っています(PR スコープ外の pre-existing deletion)。Parent Issue #813