Skip to content

Add native grok agent backend#276

Open
falkoro wants to merge 3 commits into
kunchenguid:mainfrom
falkoro:feat/grok-agent
Open

Add native grok agent backend#276
falkoro wants to merge 3 commits into
kunchenguid:mainfrom
falkoro:feat/grok-agent

Conversation

@falkoro

@falkoro falkoro commented Jun 10, 2026

Copy link
Copy Markdown

What

Adds agent: grok — a native one-shot CLI backend for the standalone grok CLI (Grok Build), modeled on the existing claude/codex/pi pattern:

  • internal/agent/grok.go: temp-file prompt (--prompt-file) so large review prompts never hit argv limits, plain-text output via --output-format plain, schema contract inlined in the prompt (same approach as pi), gitSafeEnv, classifyTransient retries, context cancellation during streaming.
  • internal/types: AgentGrok; factory case in NewWithOptions; doctor listing.
  • internal/config: agent_args_override allowlist entry + reserved flags — including --effort, which the grok API rejects (400) and must never be injected.
  • cmd/fakeagent: grok handler for the e2e harness.
  • Unit tests for construction, arg ordering (user extraArgs take precedence), schema prompt contract, and the absence of --effort.

Why

grok is a capable, cheap reviewer/writer; today the only way to route it through no-mistakes is via opencode with an xAI model, which adds a server dependency and breaks in two known ways (opencode serve rejects --model from agent_args_override, and xAI's 200-tool cap kills startup when global MCP servers are configured). A native backend removes that chain entirely.

Verification

  • gofmt clean, make lint clean
  • go test -race ./... — green except TestInitTracksCommandTelemetry, which also fails on a clean checkout of main in my environment (network-dependent)
  • make e2e green (131s)
  • Dogfooded: this branch is running as my daily gate (agent: grok + agent_path_override) reviewing a 108-file Astro monorepo diff.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings June 10, 2026 15:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for the Grok agent across configuration, detection, and execution, including a new agent implementation, fakeagent support, and unit tests.

Changes:

  • Introduces AgentGrok and wires it into agent construction and defaults.
  • Adds Grok CLI argument reservation/validation and includes Grok in doctor checks.
  • Implements grokAgent plus fakeagent Grok support and tests for prompt/arg building.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/types/types.go Adds AgentGrok constant for agent enumeration.
internal/config/config.go Registers Grok binary defaults, reserved args, and validation messaging.
internal/cli/doctor.go Adds Grok to binary presence checks.
internal/agent/agent.go Enables NewWithOptions creation for Grok and updates error message.
internal/agent/grok.go Implements Grok agent execution, prompt/args building, and retries.
internal/agent/grok_test.go Adds unit tests for Grok agent construction and helpers.
cmd/fakeagent/main.go Routes fakeagent grok invocations.
cmd/fakeagent/grok.go Implements fake Grok CLI behavior for e2e scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/agent/grok.go Outdated
Comment thread internal/agent/grok.go Outdated
Comment thread internal/agent/grok_test.go Outdated
Comment thread internal/agent/grok_test.go Outdated
falkoro and others added 3 commits June 12, 2026 08:54
One-shot CLI backend for the standalone grok CLI (Grok Build), modeled on
the claude/codex/pi pattern: prompt via temp file (--prompt-file), plain
text output, schema contract inlined in the prompt (like pi), gitSafeEnv,
classifyTransient retries, context cancellation during streaming.

- internal/agent/grok.go + grok_test.go
- types: AgentGrok; agent.go: factory case + error message
- config: agent_args_override allowlist + reserved flags (incl. --effort,
  which the grok API rejects and must never be injected)
- cmd/fakeagent: grok handler for the e2e harness

Verified: gofmt, make lint, go test -race ./... (one pre-existing
TestInitTracksCommandTelemetry failure also fails on clean upstream),
make e2e green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- stream grok stdout with a bufio.Reader (incremental ReadString) instead of a
  bufio.Scanner with a 256MB max-token buffer, avoiding a large up-front
  allocation / OOM risk on a single very long line
- correct buildGrokArgs comment: managed flags are appended last and therefore
  take precedence (and are reserved in config); the prior comment claimed the
  opposite
- drop developer-specific /home/falk/.grok/bin/grok paths from grok_test.go in
  favour of a neutral /path/to/grok

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@falkoro

falkoro commented Jun 12, 2026

Copy link
Copy Markdown
Author

Rebased onto main (v1.29.0) and addressed the review feedback in 066fc6a:

  • grok.go (stdout reading): replaced the bufio.Scanner + 256 MB max-token buffer with a bufio.Reader that reads incrementally via ReadString('\n'), so a single very long line no longer forces a large up-front allocation.
  • grok.go (buildGrokArgs comment): corrected — managed flags are appended last and therefore take precedence (grok honors the last occurrence of a flag), and these flags are reserved in config so users can't supply them. The previous comment claimed the opposite.
  • grok_test.go: dropped the developer-specific /home/falk/.grok/bin/grok paths in favour of a neutral /path/to/grok.

gofmt/go vet clean, go build and the agent tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants