feat(grok): convert interactive intake/secretary to the grok CLI; delete opencode

Move the last Grok runtime off opencode onto xAI's official `grok` CLI, for full
parity with the Claude path. The intake/secretary chat now runs per-turn headless
`grok -p` invocations that resume one session id (proven live: context carries
across runs), with streaming-json deltas mapped to the existing panel StreamChunk
kinds — the IntakeDriver loop, message source, relay, and idle reaper are reused
unchanged; only the SessionFactory differs (GrokCliSession replaces the
opencode-serve session).

- GrokCliSession + a pure, unit-tested streaming-json -> StreamChunk assembler
  (thought coalesced to one block, text streamed live, end captures the session
  id for -r, fenced-draft fallback, clear errors incl. rate-limit).
- intake propose_draft and secretary read_company_state/read_task/submit_directive
  are now FastMCP servers (roboco-intake / roboco-secretary) wired into
  ~/.grok/config.toml, launched via `uv run --directory /app` to resolve the
  installed package. The secretary tools reuse the shared backend helpers.
- Orchestrator: interactive spawn mounts the subscription auth + per-agent usage
  dir (no metered xAI key, no permission env — grok flags carry per-role perms);
  usage/cost now read a captured usage.json (drop the opencode.db reader, the
  _opencode_db_path/_grok_usage_from_opencode methods, and the cost-cap's
  opencode read). hosts["opencode"] -> hosts["grok_usage"]; OPENCODE_DATA_DIR ->
  GROK_USAGE_DATA_DIR.
- Fix one-shot usage capture: `-s` does not pin the session id (grok generates
  its own), so the entrypoint now reads the real id back from the JSON run log
  and the reader uses it; usage is captured per-turn on the interactive path.
- Delete the opencode layer: opencode_config/opencode_usage/opencode_session, the
  docker/grok/*.js plugins, the old one-shot entrypoint, and their tests.
- Compose (all three files), .env.example, and stale comments updated to the
  grok-CLI runtime; add the SuperGrok auth mount + grok-usage dir.

Gate green: ruff, mypy (296 files), xenon, tests. NAS build/verify pending.
This commit is contained in:
Renn F
2026-06-19 04:42:25 +02:00
parent 499f6fc509
commit a88045aacf
40 changed files with 1307 additions and 2200 deletions
+21 -14
View File
@@ -86,26 +86,33 @@ ROBOCO_DEFAULT_EMBEDDING_MODEL=qwen3-embedding:0.6b
# =============================================================================
# Grok (xAI) Provider — optional
# =============================================================================
# RoboCo can run agents on grok-build-0.1 (xAI) via the opencode runtime instead
# of Claude Code. The xAI API key is NOT set here — store it encrypted per
# project from the panel (provider key), the same as the Ollama/Anthropic keys.
# Every var below is optional; defaults shown.
# RoboCo can run agents on Grok Build (xAI) via xAI's official `grok` CLI on the
# SuperGrok subscription, instead of Claude Code. No metered xAI API key is used:
# the CLI authenticates from a mounted ~/.grok/auth.json — run `grok login` once
# on the host (auth.json auto-refreshes). Every var below is optional.
# Image the orchestrator spawns for Grok agents.
# Host dir holding the SuperGrok auth. The orchestrator mounts <dir>/auth.json
# read-only into each Grok agent's ~/.grok. GROK_AUTH_DIR is the host source the
# compose mounts into the orchestrator; keep both equal to the host's ~/.grok.
# ROBOCO_HOST_GROK_DIR=/home/youruser/.grok
# GROK_AUTH_DIR=/home/youruser/.grok
# Image the orchestrator spawns for Grok agents, and the CLI model id.
# ROBOCO_GROK_AGENT_IMAGE=roboco-agent-grok:latest
# ROBOCO_GROK_CLI_MODEL=grok-build
# opencode tool permissions for Grok agents: allow | ask | deny. Defaults are
# "allow"; tighten bash to "deny"/"ask" to fail closed on untrusted repos (the
# secret-scrub plugin is a denylist, not a full sandbox).
# ROBOCO_GROK_BASH_PERMISSION=allow
# ROBOCO_GROK_EDIT_PERMISSION=allow
# ROBOCO_GROK_EXTERNAL_DIR_PERMISSION=allow
# Per-role tool permissions are computed as native grok flags (subagents off;
# edit/shell removed for non-coding roles; raw git mutation + rm -rf denied for
# coding roles) — there is nothing to set here.
# Force one reasoning effort for ALL Grok agents: minimal | high | max (or empty
# for opencode's default). Empty = per-role: coordination/docs roles request
# "minimal" to cut reasoning cost, code roles keep full reasoning.
# Force one reasoning effort for ALL Grok agents: low | medium | high | xhigh |
# max (or empty for the per-role default — coordination/docs/board roles request
# "low" to cut reasoning cost, code roles keep full reasoning).
# ROBOCO_GROK_REASONING_EFFORT=
# Hard ceiling on agentic turns per run (loop guard).
# ROBOCO_GROK_MAX_TURNS=200
# Kill a Grok agent container after this many seconds idle (no model call /
# stream) to reclaim a wedged one. Minimum 120.
# ROBOCO_GROK_IDLE_KILL_SECONDS=900