Get the FREE Ultimate OpenClaw Setup Guide →

bridge-gemini

Scanned
npx machina-cli add skill mikeng-io/agent-skills/bridge-gemini --openclaw
Files (1)
SKILL.md
5.9 KB

Bridge: Gemini CLI Adapter

This file is a REFERENCE DOCUMENT. Any orchestrating skill reads it via the Read tool and embeds its instructions directly into Task agent prompts. It is not invoked as a standalone skill — it is a reusable set of instructions for Gemini CLI dispatch.

Input schema, agent prompt template, output schema, verdict logic, timeout formula, artifact format, and status semantics are defined in bridge-commons/SKILL.md. This file covers only Gemini-specific connection detection and execution.

Bridge Identity

bridge: gemini
model_family: google/gemini
availability: conditional
connection_preference:
  1: native-dispatch  # Executor is Gemini CLI — Gemini subagents (enableAgents)
  2: cli              # Any other executor — gemini -p
  3: skip             # Neither — return SKIPPED (non-blocking)

Pre-Flight — Connection Detection

Check A: Native Dispatch?

If the executor is Gemini CLI with subagent support enabled, this is the preferred path — spawn specialized Gemini subagents rather than shelling out to the CLI.

# Check if subagents are enabled in project or user settings
cat .gemini/settings.json 2>/dev/null | python3 -c \
  "import sys,json; d=json.load(sys.stdin); print(d.get('experimental',{}).get('enableAgents', False))"

# Also check user-level settings
cat ~/.gemini/settings.json 2>/dev/null | python3 -c \
  "import sys,json; d=json.load(sys.stdin); print(d.get('experimental',{}).get('enableAgents', False))"

If True and the current executor is Gemini CLI → use native dispatch (subagent path in Subagent Mode section).

If executor is not Gemini, or enableAgents is false or missing → proceed to Check B.


Check B: CLI Installed?

which gemini

If found → proceed to Check C.

If not found → return immediately:

{
  "bridge": "gemini",
  "status": "SKIPPED",
  "skip_reason": "gemini CLI not available (which gemini returned empty)",
  "outputs": [],
  "verdict": null
}

Never fail or block — SKIPPED is a valid bridge outcome.


Check C: Auth / Quota Probe

A gemini CLI that is installed but has an expired token or exhausted quota passes Check B and then fails silently at execution time. Catch this at availability check instead:

# Lightweight probe — verifies auth without a full execution
gemini --version 2>/dev/null
# Or: a minimal non-interactive list/ping command if available

If the probe exits non-zero or returns an auth error → return:

{
  "bridge": "gemini",
  "status": "SKIPPED",
  "skip_reason": "gemini CLI auth probe failed: {stderr}",
  "outputs": [],
  "verdict": null
}

If the probe succeeds → use CLI path (Execution section).


Execution

Build the prompt using the Agent Prompt Template from bridge-commons, adapting to task_type. Calculate timeout using bridge-commons formula (no bridge-specific multiplier for Gemini).

TIMEOUT={calculated_timeout}
PROMPT="{constructed_prompt}"

timeout $TIMEOUT gemini -p "$PROMPT" --approval-mode plan --output-format json

Error handling:

  • Exit code 0 with JSON → parse and return findings
  • Exit code 124 (timeout) → return SKIPPED with reason timeout_after_{n}s
  • Other exit codes → return SKIPPED with reason gemini CLI error: {stderr}
  • Invalid JSON output → attempt to extract structured content, else SKIPPED

After execution, run the bridge-commons Post-Analysis Protocol. Gemini uses stateless context passing between rounds — embed the full previous-round outputs and context packet in each subsequent gemini -p call. There is no session continuity between separate CLI invocations.

For standard and thorough intensity, construct the Round 2 prompt as:

{Agent Prompt Template for this role}

--- ROUND 2 CONTEXT ---
Previous round findings:
{JSON of all Round 1 outputs}

{context packet: open_challenges directed at this domain, synthesis}

Never block the calling orchestrator — always return a report (even if SKIPPED).


Subagent Mode

Gemini CLI supports custom subagents for parallel domain dispatch when experimental.enableAgents is set in .gemini/settings.json.

# Confirm subagents are enabled
cat .gemini/settings.json 2>/dev/null | python3 -c \
  "import sys,json; d=json.load(sys.stdin); print(d.get('experimental',{}).get('enableAgents', False))"
  • If true → spawn one subagent per domain; run consolidation pass after all complete
  • If false or missing → run standard single Gemini call covering all domains (valid fallback)

Subagent mode is a progressive enhancement. Record subagent_mode: true/false in output.


Output

See bridge-commons Output Schema. Bridge-specific fields:

{
  "bridge": "gemini",
  "model_family": "google/gemini",
  "connection_used": "native-dispatch | cli",
  "subagent_mode": true
}

Output ID prefix: G (e.g., G001, G002).


Notes

  • Always check availability first — never assume gemini is installed
  • Use non-interactive mode only; always specify --approval-mode
  • Use --output-format json for structured parsing (not -o json)
  • Timeout is estimated from scope, not hardcoded — see bridge-commons formula
  • SKIPPED is a valid, non-error outcome

Analysis safety: Use --approval-mode plan for all non-implementation task types. This prevents Gemini from auto-applying file edits during review/audit/research tasks. For implementation tasks (task_type = implementation), auto_edit may be appropriate.

Source

git clone https://github.com/mikeng-io/agent-skills/blob/master/skills/bridge-gemini/SKILL.mdView on GitHub

Overview

The Bridge: Gemini CLI Adapter is a reference dispatch guide used by orchestrating skills via the Read tool. It defines how to invoke Gemini CLI in non-interactive mode, how timeout and fallback behavior are handled, and is usable by deep-council, deep-review, deep-audit, or any future skill needing Gemini-based review. It is not a stand-alone skill; it provides reusable Gemini CLI dispatch instructions.

How This Skill Works

Orchestrating skills determine Gemini availability through a sequence of checks (native-dispatch with subagents, CLI presence, and a quick auth probe). When execution proceeds, it builds a non-interactive prompt using the bridge-commons Agent Prompt Template, calculates a timeout with the shared formula, and runs gemini -p with the prepared prompt. The output is parsed as JSON findings or yields SKIPPED with a specific reason on timeout or errors, then the Post-Analysis Protocol runs with stateless context passing per the bridge-commons workflow.

When to Use It

  • When you need a Gemini-based review as part of an orchestrated task (e.g., deep-review, deep-audit).
  • When running in non-interactive, automated pipelines that require Gemini CLI dispatch.
  • When you want to validate Gemini CLI availability and auth before broader use.
  • When you prefer a SKIPPED outcome rather than blocking if Gemini isn’t installed.
  • When coordinating with bridge-commons-enabled skills to propagate context across rounds.

Quick Start

  1. Step 1: Ensure the Gemini CLI is installed and accessible (e.g., which gemini).
  2. Step 2: Build the agent prompt via the bridge-commons template and calculate TIMEOUT, then run gemini -p "$PROMPT" --approval-mode plan --output-format json.
  3. Step 3: Parse the JSON output or handle SKIPPED reasons per the protocol; continue with the Post-Analysis steps.

Best Practices

  • Prefer native-dispatch subagents if enableAgents is true and Gemini CLI is detected, to use the subagent path.
  • Always perform the A-C pre-flight checks (subagents, CLI presence, auth probe) before execution.
  • Use the bridge-commons Agent Prompt Template and the shared timeout formula for consistency.
  • Treat non-zero exits or JSON parsing failures as SKIPPED with clear, actionable reasons.
  • Embed full previous-round outputs and context in the subsequent round per the bridge-commons protocol.

Example Use Cases

  • A deep-review orchestrator invokes Gemini via this bridge to analyze a batch of documents non-interactively.
  • An audit workflow uses Gemini CLI to summarize findings and returns structured JSON for auditing teams.
  • A council-style skill aggregates multiple sources, dispatching Gemini for consensus-style insights.
  • If Gemini CLI is not installed, the bridge yields SKIPPED with a clear skip_reason and continues the workflow.
  • A test harness validates GeminI auth and output handling across multiple rounds using the Post-Analysis Protocol.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers