Gateguard

From affaan-m/ECC · View interactive version

Gateguard is an AI agent skill from the GitHub repository affaan-m/ECC. API、エージェント、およびLLMエンドポイントのアクセス制御と認可パターン。

How to use this skill

Skill file

GateGuard — Fact-Forcing Pre-Action Gate

A PreToolUse hook that forces Claude to investigate before editing. Instead of self-evaluation ("are you sure?"), it demands concrete facts. The act of investigation creates awareness that self-evaluation never did.

When to Activate

Core Concept

LLM self-evaluation doesn't work. Ask "did you violate any policies?" and the answer is always "no." This is verified experimentally.

But asking "list every file that imports this module" forces the LLM to run Grep and Read. The investigation itself creates context that changes the output.

Three-stage gate:

1. DENY  — block the first Edit/Write/Bash attempt
2. FORCE — tell the model exactly which facts to gather
3. ALLOW — permit retry after facts are presented

No competitor does all three. Most stop at deny.

Evidence

Two independent A/B tests, identical agents, same task:

| Task | Gated | Ungated | Gap |

| --- | --- | --- | --- |

| Analytics module | 8.0/10 | 6.5/10 | +1.5 |

| Webhook validator | 10.0/10 | 7.0/10 | +3.0 |

| Average | 9.0 | 6.75 | +2.25 |

Both agents produce code that runs and passes tests. The difference is design depth.

Gate Types

Edit / MultiEdit Gate (first edit per file)

MultiEdit is handled identically — each file in the batch is gated individually.

NotebookEdit は notebook_path への Edit として扱われます(同じクラス・チェック済みキー・クレジット・上限の規則。セル内容は読まないため常に完全な質問になり、コメントのみの通過はありません)。

質問内容は対象ファイルのクラスによって変わります(対象クラス別の質問を参照)。以下は code クラスの Edit ゲートの質問です。

Before editing {file_path}, present these facts:

1. List ALL files that import/require this file (search the tree — Glob/Grep, or find/grep via Bash)
2. List the public functions/classes affected by this change
3. If this file reads/writes data files, show field names, structure,
   and date format (use redacted or synthetic values, not raw production data)
4. Quote the user's current instruction verbatim

Write Gate (first new file creation)

以下は code クラスの Write ゲートの質問です。

Before creating {file_path}, present these facts:

1. Name the file(s) and line(s) that will call this new file
2. Confirm no existing file serves the same purpose (search the tree — Glob/Grep, or find/grep via Bash)
3. If this file reads/writes data files, show field names, structure,
   and date format (use redacted or synthetic values, not raw production data)
4. Quote the user's current instruction verbatim

対象クラス別の質問

初回の Edit/Write ゲートは対象ファイルを分類し、最初に一致したクラスの質問を使います。分類にはプロジェクトルート(CLAUDE_PROJECT_DIR、次にペイロードの cwd、次にプロセスのディレクトリ)からの相対パスを使うため、~/work/tests/ のような場所にあるプロジェクトでも全ファイルが test になることはありません。先頭の .claude/worktrees/<name>/ は <root>/.claude/worktrees/<name>/.git が存在する場合にだけ取り除きます。Windows 形式のパスでは末尾のドット・空白と :stream 接尾辞を除いてから分類します(CLAUDE.md. や CLAUDE.md::$DATA は CLAUDE.md として扱います)。ルート外の対象は絶対パスで分類します。パスは小文字化・/ 区切りで、次の順に判定します。

  1. instruction — CLAUDE.md、AGENTS.md、AGENT.md、GEMINI.md、SKILL.md、copilot-instructions.md、.cursorrules、.windsurfrules、任意の .mdc、.claude、agents、commands、skills、rules、hooks、.cursor、.codex、.opencode ディレクトリ配下の .md/.mdx/.txt、または .github/ 配下の *instructions*.md
  2. test — *.test.*、*.spec.*、test_*.py、*_test.py、*_test.go、または tests、test、__tests__ 配下
  3. prose — .md、.mdx、.txt、.rst、.adoc
  4. config — .json、.jsonc、.yaml、.yml、.toml、.ini、またはコード拡張子で終わらない .env / .env.*(.env.local は config、.env.example.ts と .envrc は code)
  5. code — 上記以外(上に示した質問)

どのクラスも最後に「ユーザーの現在の指示を原文のまま引用する」項目が付きます。質問文(英語、hook の出力そのまま)は次のとおりです。(search) は "(search the tree — Glob/Grep, or find/grep via Bash)" の略です。

| クラス | 質問 |

|---|---|

| instruction | Name the harness/loader that reads this file (Claude Code, Codex, Cursor, OpenCode, …) and when it loads it · Describe what agent behaviour changes as a result · Confirm no existing instruction, skill, or agent file already covers this (search) |

| test | Name what behaviour is under test and which module/function it exercises · Name the existing test file(s) covering this module, or confirm none exist (search) |

| prose (Write) | Name any existing doc this supersedes or duplicates (search) · State where it will be linked or referenced from · Explain why a new file rather than editing an existing one |

| prose (Edit) | List other docs or code that reference the section being changed (search) · State what the change corrects or adds |

| config | Name which process/tool reads this file and when · Describe the effect of the change · Confirm no secrets or credentials are being written in plain text |

code クラスでは変更内容も読み、公開宣言に触れない Edit には importer/公開 API の代わりに「このファイルまたはモジュール内で変更された振る舞いに依存する呼び出し箇所」を尋ね、データを扱わない変更ではデータ形式の質問を省きます(未対応の拡張子、64 KiB 超などの判定不能な変更と機密対象では従来の 4 問のままです)。

メッセージの文面以外でクラスが影響するのは兄弟ファイル集約だけです(集約できるクラスと、同じクラス同士でのみ集約されること)。

Destructive Bash Gate (every destructive command)

Triggers on: rm -rf, git reset --hard, git push --force, drop table, drop database, drop schema, alter table ... drop column, etc.

1. List all files/data this command will modify or delete
2. Write a one-line rollback procedure
3. Quote the user's current instruction verbatim

Routine Bash Gate (once per session)

1. The current user request in one sentence
2. What this specific command verifies or produces

このゲートが発火するまでは、読み取り専用のコマンド(ls、cat、rg、git status/log/diff、Get-ChildItem など。リダイレクト、置換、tee、xargs、未知のコマンドを含まないもの)はゲートを消費せずに通過し routine_readonly_passes に数えます。セッション ID またはトランスクリプトパスで識別される状態は 8 時間、プロジェクトディレクトリによるフォールバックは 30 分の無操作で失効し、サブエージェントでも機密対象はパスごとに 1 回拒否されます(親のゲートは解除されません)。

すでに済んでいるとみなされるもの

調査がすでに行われたことがトランスクリプトから確認できる場合、または前回の拒否と同じ回答になる場合、ゲートは拒否の代わりに注記(additionalContext)付きで通過させます。判断が曖昧な場合は常に従来どおり拒否します。

Quick Start

Option A: Use the ECC hook (zero install)

The hook at scripts/hooks/gateguard-fact-force.js is included in this plugin. Enable it via hooks.json.

If GateGuard blocks setup or repair work, start the session with

ECC_GATEGUARD=off. For hook-level control, keep using

ECC_DISABLED_HOOKS with the GateGuard hook ID.

Option B: Full package with config

pip install gateguard-ai
gateguard init

This adds .gateguard.yml for per-project configuration (custom messages, ignore paths, gate toggles).

Anti-Patterns

Best Practices

Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.