mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-17 04:15:21 +00:00
Add Grok Build support (context, setup, native hooks)
Adds first-class support for xAI's Grok Build CLI, following the
existing client-integration pattern (Claude Code, CodeBuddy, Codex):
- grok context: single-project, shaped like claude-code.yml, with the
file-tool exclusions appropriate for a CLI agent that has its own
read/edit/shell tools. structured_tool_output is left at the auto
default (as in the codex and codebuddy contexts); claude-code's
explicit false is a Claude-Code-specific bug workaround that is not
carried over.
- serena setup grok: registers Serena as a user-scoped MCP server via
"grok mcp add" after detecting a compatible grok CLI.
- serena-hooks --client=grok: Grok-native PreToolUse output
({decision, reason}) instead of the Claude-style hookSpecificOutput
envelope; grep/read detection extended to Grok's tool names and
shell payloads (target_file/targetFile path keys, non-string command
values handled defensively). The payload-parsing refinements live in
the remind hook's client-agnostic parsing and apply to all hook
clients: a non-string command value previously raised, and
target_file/targetFile paths were not recognized.
- Docs (030_clients.md #grok), unit tests for setup/hooks/context, and
scripts/live_test_grok.py - a zero-inference, state-preserving live
smoke test against a real grok installation (documented in
CONTRIBUTING.md). Its M5 check verifies the structured-output wire
shape: the grok context (auto default) serves an output schema and
structuredContent for string-returning tools, while the claude-code
context (explicit false workaround) serves plain text only.
This commit is contained in:
1 parent
96ee9b65e2
commit
9debf7742a
13 files changed
+2122
-8
No files matched your search
@@ -380,6 +380,88 @@ The hooks will:
|
||||
The `PreToolUse` matcher is intentionally restricted to `Bash`. The Serena reminder hook for Codex
|
||||
tracks shell-based grep and code-file reads, so running it for every tool call is unnecessary.
|
||||
|
||||
## Grok
|
||||
|
||||
Serena provides native support for xAI's Grok Build CLI. To set up the Serena MCP server for Grok,
|
||||
simply run:
|
||||
|
||||
serena setup grok
|
||||
|
||||
### Manual Setup
|
||||
|
||||
**Global Configuration**. To add the Serena MCP server for all your projects, use Grok's user-level configuration and the `--project-from-cwd` flag:
|
||||
|
||||
```bash
|
||||
grok mcp add --scope user serena -- serena start-mcp-server --context=grok --project-from-cwd
|
||||
```
|
||||
|
||||
Alternatively, add the following to `~/.grok/config.toml`:
|
||||
|
||||
```toml
|
||||
[mcp_servers.serena]
|
||||
command = "serena"
|
||||
args = ["start-mcp-server", "--project-from-cwd", "--context=grok"]
|
||||
```
|
||||
|
||||
**Project-Level Configuration**. To add the Serena MCP server for a single project only:
|
||||
|
||||
```bash
|
||||
grok mcp add --scope project serena -- serena start-mcp-server --context=grok --project "$(pwd)"
|
||||
```
|
||||
|
||||
**Verification.**
|
||||
Run `grok inspect` and verify that Serena is listed as an MCP server. You can also use Grok's `/mcps`
|
||||
modal to inspect, refresh, enable, or disable configured MCP servers.
|
||||
|
||||
Grok can also load existing Claude Code MCP configuration. If you previously ran `serena setup claude-code`,
|
||||
Serena may already appear in Grok, but it will use the `claude-code` context instead of the dedicated `grok` context.
|
||||
|
||||
### Hooks
|
||||
|
||||
Grok supports lifecycle hooks; see Grok's bundled hooks documentation for details. To enable Serena's hooks
|
||||
for Grok globally, create `~/.grok/hooks/serena-hooks.json` with the following content. For a single project,
|
||||
create `.grok/hooks/serena-hooks.json` in that project instead; note that Grok loads project-scoped hooks
|
||||
only after you have trusted the project for hook execution (via Grok's `/hooks-trust` command).
|
||||
|
||||
```json
|
||||
{
|
||||
"hooks": {
|
||||
"PreToolUse": [
|
||||
{
|
||||
"matcher": "grep|read_file|run_terminal_command",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "serena-hooks remind --client=grok",
|
||||
"timeout": 5
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"Stop": [
|
||||
{
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "serena-hooks cleanup --client=grok",
|
||||
"timeout": 5
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The hooks will:
|
||||
|
||||
- **`remind`**: Nudge the agent to use Serena's symbolic tools when it makes too many consecutive
|
||||
code-search or code-file-read calls without using Serena tools in between.
|
||||
- **`cleanup`**: Clean up hook session data when the agent turn ends.
|
||||
|
||||
Grok ignores stdout from passive hooks such as `SessionStart`, so the Grok hook setup intentionally
|
||||
uses only `PreToolUse` for reminders and `Stop` for cleanup.
|
||||
|
||||
## Claude Desktop
|
||||
|
||||
On Windows and macOS, there are official [Claude Desktop applications by Anthropic](https://claude.ai/download); for Linux, there is an [open-source
|
||||
|
||||
@@ -73,6 +73,7 @@ Serena comes with pre-defined contexts:
|
||||
The full set of Serena's tools is provided, as the application is assumed to have no prior coding-specific capabilities.
|
||||
* `claude-code`: Optimized for use with Claude Code, it disables tools that would duplicate Claude Code's built-in capabilities.
|
||||
* `codex`: Optimized for use with OpenAI Codex.
|
||||
* `grok`: Optimized for use with xAI's Grok Build CLI.
|
||||
* `ide`: Generic context for IDE assistants/coding agents, e.g. VSCode, Cursor, or Cline, focusing on augmenting existing capabilities.
|
||||
Basic file operations and shell execution are assumed to be handled by the assistant's own capabilities.
|
||||
* `agent`: Designed for scenarios where Serena acts as a more autonomous agent, for example, when used with Agno.
|
||||
@@ -81,7 +82,7 @@ Choose the context that best matches the type of integration you are using.
|
||||
|
||||
Find the concrete definitions of the above contexts [here](https://github.com/oraios/serena/tree/main/src/serena/resources/config/contexts).
|
||||
|
||||
Note that the contexts `ide` and `claude-code` are **single-project contexts** (defining `single_project: true`).
|
||||
Note that the contexts `ide`, `claude-code`, and `grok` are **single-project contexts** (defining `single_project: true`).
|
||||
For such contexts, if a project is provided at startup, the set of tools is limited to those required by the project's
|
||||
concrete configuration, and other tools are excluded completely, allowing the set of tools to be minimal.
|
||||
Tools explicitly disabled by the project will not be available at all. Since changing the active project
|
||||
|
||||
Reference in new issue
Block a user