Commit Graph

4 Commits

Author SHA1 Message Date
a63f477463 feat(gemini): plexum-host MCP exposure + real consume mirror
Same architecture as the codex sister change:

1. mcp-host subcommand routes argv[1] to mcpbridge.Run, reading
   PLEXUM_MCP_SOCKET / PLEXUM_MCP_AGENT_ID from gemini-cli's
   `gemini mcp add --env` env baking.

2. EnsureGeminiMCPRegistered handles per-agent stable registration
   under `-s user --trust` so gemini auto-approves the tool surface.

3. Post-turn ParseGeminiToolCalls + EmitGeminiToolCalls scans the
   chat JSONL at ~/.gemini/tmp/<ws>/chats/session-*.jsonl. Pairs
   gemini's nested `toolCalls[].id` with the matching
   `functionResponse.id` from later user lines.

4. MutateGeminiSession rewrites the chat JSONL: toolCalls[].args
   → {} (heavy), functionResponse.response.output → marker.

E2E verified: gemini call exec via plexum-host → dynamic.jsonl
records the call → dynamic-tool-clear consumes → gemini session
mirrored → resume gemini sees consumed marker not the original.
2026-06-01 20:14:13 +01:00
dbe68a889c feat(gemini): SessionMutator stub + session-file resolver
Wires the host's mirror hook end-to-end: FindGeminiSessionFile resolves
~/.gemini/tmp/<workspace>/chats/session-<ISO>-<sid_prefix>.jsonl from
the session id captured into .plexum-gemini-session, picking the
most-recent match by mtime. Logs the no-op for telemetry.

Real rewrite is deferred to v2: gemini-cli's tool-call id namespace
doesn't match Plexum's canonical block format (and its on-disk shape
is `$set`-style mutation log rather than flat append-only). When
tool-call round-trip through gemini's native surface lands, the
rewriter plugs into this file's path resolver.
2026-06-01 14:01:33 +01:00
fab4e70c84 fix(runner): write session id atomically (tmp+rename)
Aligns with anthropic-contractor: a crash mid-write leaves a stale
.plexum-gemini-session.tmp instead of an empty real file that would
make the next turn start fresh and lose context.
2026-06-01 13:45:07 +01:00
4f98428e1c feat: Plexum-gemini-provider v0.1 — Google Gemini via local CLI binary
Plexum ProviderPlugin that wraps the local `gemini` CLI binary
(Google Gemini CLI ≥0.37). Same CLI-driven approach as
Plexum-anthropic-provider's contractor mode: each Plexum turn forks
one `gemini -p` subprocess in the agent's workspace dir.

Reference: openclaw/extensions/google/cli-backend.ts.

internal/runner/ (~190 LOC):
- Run() spawns: gemini --skip-trust --output-format json [--model X]
  [--resume <sid>] -p <prompt> in agent workspace
- Parses the single JSON blob gemini emits at exit
  ({"session_id":"...", "response":"...", "stats":{...}})
- session_id persisted at <workspace>/.plexum-gemini-session so the
  next turn passes --resume — multi-turn context continuity through
  the CLI's own session state
- Emits synthetic message_start + text_delta + message_end events to
  match Plexum's streaming agentic-loop contract
- Tolerates the "Ripgrep is not available." stderr preamble (strips
  leading non-{ bytes before json.Unmarshal)

cmd/plexum-gemini-provider-plugin/ implements ProviderPluginWithAgent
(receives AgentContext.Workspace from the host).

Models advertised in provider.models:
  gemini             (no --model flag; CLI default = flash-preview)
  gemini-pro         → CLI alias "pro"        → gemini-3.1-pro-preview
  gemini-flash       → CLI alias "flash"      → gemini-3.1-flash-preview
  gemini-flash-lite  → CLI alias "flash-lite" → gemini-3.1-flash-lite-preview

Unrecognized model id passes through as --model <id> so operator can
pin a specific gemini-3.x id.

HostConfig (all optional):
  binary       (default "gemini" — operator should set absolute path
                if running under systemd; PATH won't include nvm dirs)
  extra_args   (appended before -p)

No api_key field — gemini CLI handles auth via ~/.gemini/ state
(OAuth or GEMINI_API_KEY env).

End-to-end verified against local install:

1. CLI embedded turn 1:     "Hi, I'm Gemini, your autonomous CLI
                              agent for software engineering tasks."
2. CLI embedded turn 2:     "I said hi as Gemini." (multi-turn ✓ via
                            --resume)
3. Gateway socket:          {"outcome":"text","text":"pong"}
4. Fabric channel e2e:      alice → bt2-clean → gem agent → gemini
                            CLI → outbound REST → seq=19:
                            "A shrimp's heart is located in its head,
                             which is quite an unusual biological
                             arrangement."

Known: when daemon runs under systemd, PATH doesn't include nvm
dirs by default. Operator must set the absolute binary path in
config.json (README notes this).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 16:44:35 +01:00