@weave_protocol/adapter-geminicli
v0.3.0
Published
Weave Protocol adapter for Gemini CLI - enforces WARD.md policies via Gemini CLI's BeforeTool hook
Maintainers
Readme
🛡️ @weave_protocol/adapter-geminicli
Enforce WARD.md in Gemini CLI with its
BeforeToolhook. Every tool call the agent makes is checked against your policy before it runs.
The fourth WARD harness adapter, after Claude Code, Antigravity and Microsoft Agent Framework. The same WARD.md works in all of them.
🆕 What's new
0.3.0: session and spend limits. WARD.md's limits are now enforced per session, keyed on the Gemini CLI session_id:
- Behavioral Limits:
maxToolCalls,maxRuntimeSecondsandmaxExternalServices; spending_limits:caps: tool calls, and per-tool call counts and USD amounts over a run, hour, day, week or month.
The counts live in a small local ledger (~/.weave/ledger, or $WEAVE_LEDGER_DIR) because every hook call is a new process. Ward 0.3.6's payment guard also asks before any call that moves money: payment tools, and wallet or Stripe CLIs in shell commands.
Quick start
npm i -g @weave_protocol/adapter-geminicli
weave-gemini init # adds the hook to ~/.gemini/settings.json
weave-gemini status # hook installed? which WARD.md is active?Then restart Gemini CLI. Add a WARD.md to your project (npx @weave_protocol/ward init), or a user-wide one at ~/.gemini/WARD.md.
What it checks
The hook uses Ward's shared evaluator (evaluateToolCall), so the rules match the other adapters exactly:
- Capability: the tool's WARD capability (
run_shell_command→shell_exec,read_file→file_read, …) or its raw name. - Arguments: every path and URL argument, with
..and~normalized, including every entry ofread_many_files'includelist. - Shell commands: every URL and every absolute or
~path inrun_shell_command, with relative paths resolved against itsdir_path. web_fetch: every URL inside its free-textprompt.- MCP tools (
mcp_<server>_<tool>): by name, plus their path and URL arguments.
Gemini CLI's planning and interaction tools (ask_user, write_todos, plan mode, the task tracker, update_topic) share one capability, task_planning, so a default-deny policy can allow them in one line:
## Capabilities
allow:
- file_read
- task_planning
default: denyDecisions
| WARD decision | What Gemini CLI sees |
|---|---|
| allow | nothing ({}): Gemini CLI's own confirmation prompts still apply |
| deny | {"decision": "deny", "reason": "WARD: …"}; the reason goes to the agent as the tool error |
| require_approval | a deny whose reason says approval is needed (Gemini CLI hooks have no "ask") |
Failure modes:
- An invalid WARD.md always denies, so a typo can't silently switch enforcement off.
- No WARD.md anywhere means no enforcement.
- Malformed payloads and evaluator errors allow by default.
weave-gemini init --fail-closedmakes them deny.
WARD.md is looked up in this order:
$WEAVE_WARD_PATH<project>/WARD.md<project>/.gemini/WARD.md<project>/.weave/WARD.md~/.gemini/WARD.md
Commands
weave-gemini init [--matcher=REGEX] [--timeout=MS] [--fail-closed]
weave-gemini disable
weave-gemini status
weave-gemini test read_file --input='{"file_path":"secrets/key"}' # dry run
weave-gemini hook before-tool # what Gemini CLI runsinit backs up settings.json, edits it atomically, and finds its own entry by the hook name weave-ward, so your other hooks are untouched. It installs at user level. Gemini CLI fingerprints project-level hooks and warns when one changes, but a user-level hook covers every project.
Dashboard
Set WEAVE_DASHBOARD_URL (and WEAVE_API_KEY) where you run the agent, and each decision is reported to a local Weave API dashboard (0.2.0+). Only the decision and the tool name are sent, never command or argument contents. Reporting never changes a decision and gives up after 250 ms.
Verified
Built against the hooks reference and tools reference. Live-checked in Gemini CLI 0.66.0: a read_file of a denied path was blocked with the WARD reason, and an allowed read went through.
🕸️ Part of Weave Protocol
One WARD.md policy for every agent you run, locally or at scale, plus the tools around it.
| Package | What it does | |---|---| | Ward | The WARD.md policy standard and the tool-call evaluator every adapter shares | | Mund | Scans content for prompt injection, secrets, PII and exfiltration | | Hord | Encrypted vaults, PII tokenization, sandboxes, capability tokens, attestations | | Dōmere | Audit threads, compliance checkpoints, GDPR and CCPA records, anchoring | | Witan | Multi-agent consensus and spending caps | | Hundredmen | MCP proxy that enforces WARD.md on tool calls | | Tollere | Supply-chain checks: typosquats, CVEs, suspicious version diffs | | Browser | WARD.md and injection scanning for Playwright browser agents | | Adapters | WARD.md in Claude Code, Antigravity, MSAF, Gemini CLI, Codex, OpenCode and Cursor | | Adversary · AgentSecBench | Red-team engine and locked benchmark | | API · CLI · LangChain | REST API and dashboard, setup CLI, LangChain.js integration | | full | Every defensive package in one install | | Yoxallismus | Post-quantum hybrid cipher (experimental beta) |
License
Apache-2.0
