Skip to content

Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.

feat(hosts): add Grok (xAI) as a graft init host (#184)

Stawiari4a3e0b22246e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8971c273..54e01116 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,10 @@
### Added
+- **Grok (xAI) is a first-class `graft init` host.** Detects `~/.grok` or a
+ repo `.grok/` and writes `.grok/skills/graft/SKILL.md` plus a repo-level
+ `[mcp_servers.graft]` block in `.grok/config.toml` (Grok's MCP config).
+ Select it with `graft init --agents grok`.
- **R language support.** `tree-sitter-r` (`npm:@davisvaughan/tree-sitter-r`;
the unscoped npm name is a squatted placeholder) parses `.R`/`.r` files.
Plain functions: every `name <- function(...)` / `name = function(...)` /
diff --git a/README.md b/README.md
index 760e1e1f..d75d2358 100644
--- a/README.md
+++ b/README.md
@@ -255,13 +255,13 @@ npx @nanonets/graft init
# Claude Code additionally gets the live statusline + hooks below
```
-On a terminal, `init` shows you every agent it knows about — flagging the ones it detected (via their config directories) and listing the exact files each would write — and wires only the ones you select. Claude Code is pre-selected; nothing else is. Selected agents get a marker-fenced Graft section in their shared instruction file — `AGENTS.md` (Codex, OpenCode and other CLIs that read it), `GEMINI.md`, `.github/copilot-instructions.md` — or a wholly-owned rule/skill file for the agents that use one: `.claude/skills/graft/SKILL.md`, `.cursor/rules/graft.mdc`, `.kiro/steering/graft.md`, `.windsurf/rules/graft.md`, `.adal/skills/graft/SKILL.md` for [AdaL](https://adal.sylph.ai). Claude Code is in the second group: `init` writes its own skill file and never touches your `CLAUDE.md`. Re-running only updates Graft's own section (or replaces the owned file) and never touches the rest of your content.
+On a terminal, `init` shows you every agent it knows about — flagging the ones it detected (via their config directories) and listing the exact files each would write — and wires only the ones you select. Claude Code is pre-selected; nothing else is. Selected agents get a marker-fenced Graft section in their shared instruction file — `AGENTS.md` (Codex, OpenCode and other CLIs that read it), `GEMINI.md`, `.github/copilot-instructions.md` — or a wholly-owned rule/skill file for the agents that use one: `.claude/skills/graft/SKILL.md`, `.cursor/rules/graft.mdc`, `.kiro/steering/graft.md`, `.windsurf/rules/graft.md`, `.grok/skills/graft/SKILL.md` for Grok (xAI), `.adal/skills/graft/SKILL.md` for [AdaL](https://adal.sylph.ai). Claude Code is in the second group: `init` writes its own skill file and never touches your `CLAUDE.md`. Re-running only updates Graft's own section (or replaces the owned file) and never touches the rest of your content.
With no TTY to prompt on — CI, a Dockerfile, a piped shell — `init` writes **nothing** and prints the command to run instead. Pass `--agents <ids>` or `--yes` to make a scripted run explicit.
| Flag | Effect |
|---|---|
-| `--agents <ids...>` | wire only these, no prompt — ids: `agents`, `cursor`, `gemini`, `copilot`, `kiro`, `windsurf`, `adal`, `claude` |
+| `--agents <ids...>` | wire only these, no prompt — ids: `agents`, `cursor`, `gemini`, `grok`, `copilot`, `kiro`, `windsurf`, `adal`, `claude` |
| `--yes`, `-y` | skip the prompt and wire every **detected** agent |
| `--dry-run` | print every file `init` would touch, then exit without writing |
| `--all-agents` | write instruction files for every known agent, detected or not |
@@ -374,7 +374,7 @@ graft viz --export site/ --title "PR #12" # one self-contained index.html — f
graft init [dir] # pick which agents to wire (prompts on a terminal; writes nothing until you choose)
graft init --dry-run # list every file it would touch, then exit
-graft init --agents cursor kiro # wire only these agents, no prompt (ids: agents, cursor, gemini, copilot, kiro, windsurf, adal, claude)
+graft init --agents cursor kiro # wire only these agents, no prompt (ids: agents, cursor, gemini, grok, copilot, kiro, windsurf, adal, claude)
graft init --yes # no prompt; wire every detected agent
graft init --no-global # skip writes outside this repo (~/.codex/ config + hooks)
graft init --no-build # wire the files only; don't build the graph
diff --git a/node_modules b/node_modules
new file mode 120000
index 00000000..9cf9293f
--- /dev/null
+++ b/node_modules
@@ -0,0 +1 @@
+/Users/shrishdwivedi/Documents/Context graphs/context-graph-engine/node_modules
\ No newline at end of file
diff --git a/src/hosts/mcp-config.ts b/src/hosts/mcp-config.ts
index 8a811954..878ce0c8 100644
--- a/src/hosts/mcp-config.ts
+++ b/src/hosts/mcp-config.ts
@@ -156,6 +156,14 @@ export function mcpTargets(
case 'kiro':
out.push(jsonTarget(id, id, join(repo, '.kiro', 'settings', 'mcp.json'), 'mcpServers', entry));
break;
+ case 'grok':
+ // Grok reads MCP from repo-level `.grok/config.toml` (`[mcp_servers.<name>]`),
+ // the same TOML shape Codex uses at ~/.codex/config.toml.
+ out.push({
+ hostId: id, id: 'grok', path: join(repo, '.grok', 'config.toml'),
+ scope: 'repo', kind: 'mcp', what: '[mcp_servers.graft]', format: 'toml',
+ });
+ break;
case 'agents':
// Guarded on the CLI actually being installed, so a plan only ever
// lists files a real run would touch.
diff --git a/src/hosts/registry.ts b/src/hosts/registry.ts
index 1380797e..9bc4e4a7 100644
--- a/src/hosts/registry.ts
+++ b/src/hosts/registry.ts
@@ -62,6 +62,14 @@ export const HOSTS: HostTarget[] = [
content: instructionBody,
detect: (p) => p.dirExists(join(p.home, '.gemini')),
},
+ {
+ id: 'grok',
+ name: 'Grok (xAI)',
+ kind: 'owned',
+ relPath: join('.grok', 'skills', 'graft', 'SKILL.md'),
+ content: skillTemplate,
+ detect: (p) => p.dirExists(join(p.home, '.grok')) || p.dirExists(join(p.repo, '.grok')),
+ },
{
id: 'hermes',
name: 'Hermes Agent (Nous Research)',
diff --git a/test/hosts-init.test.ts b/test/hosts-init.test.ts
index 0925bfb4..cbbd3c37 100644
--- a/test/hosts-init.test.ts
+++ b/test/hosts-init.test.ts
@@ -34,7 +34,7 @@ test('explicit agents list overrides detection and flags unknown ids', () => {
test('all writes every host and re-run converges (idempotent)', () => {
const home = fresh(); const repo = fresh();
const first = runHostsInit(repo, { home, all: true });
- assert.equal(first.written.length, 9);
+ assert.equal(first.written.length, 10);
const second = runHostsInit(repo, { home, all: true });
assert.ok(second.written.every((w) => w.action === 'unchanged'));
// `agents` and `antigravity` share AGENTS.md, but the fenced section is written once
diff --git a/test/hosts-mcp-config.test.ts b/test/hosts-mcp-config.test.ts
index 8c819092..f6596670 100644
--- a/test/hosts-mcp-config.test.ts
+++ b/test/hosts-mcp-config.test.ts
@@ -69,6 +69,17 @@ test('codex TOML append preserves existing content', () => {
assert.match(toml, /\[mcp_servers\.graft\]/);
});
+test('grok gets a repo-local TOML MCP section', () => {
+ const repo = fresh(); const home = fresh();
+ const w = registerMcpConfigs(repo, ['grok'], { home });
+ assert.deepEqual(w.map((x) => x.action), ['created']);
+ const toml = readFileSync(join(repo, '.grok', 'config.toml'), 'utf8');
+ assert.match(toml, /^\[mcp_servers\.graft\]$/m);
+ assert.match(toml, /"@nanonets\/graft"/);
+ const again = registerMcpConfigs(repo, ['grok'], { home });
+ assert.deepEqual(again.map((x) => x.action), ['unchanged']);
+});
+
test('JSON with non-object mcpServers value is skipped', () => {
const repo = fresh(); const home = fresh();
mkdirSync(join(repo, '.cursor'), { recursive: true });
diff --git a/test/hosts-registry.test.ts b/test/hosts-registry.test.ts
index db870853..76153ad4 100644
--- a/test/hosts-registry.test.ts
+++ b/test/hosts-registry.test.ts
@@ -15,7 +15,7 @@ function probeFor(home: string, repo: string): DetectProbe {
function fresh(): string { return mkdtempSync(join(tmpdir(), 'graft-registry-')); }
test('registry exposes the known hosts', () => {
- assert.deepEqual(hostIds().sort(), ['adal', 'agents', 'antigravity', 'copilot', 'cursor', 'gemini', 'hermes', 'kiro', 'windsurf']);
+ assert.deepEqual(hostIds().sort(), ['adal', 'agents', 'antigravity', 'copilot', 'cursor', 'gemini', 'grok', 'hermes', 'kiro', 'windsurf']);
for (const h of HOSTS) {
assert.ok(h.relPath.length > 0);
assert.ok(h.content().length > 0);
@@ -57,6 +57,20 @@ test('repo-local .adal also lights up the adal host', () => {
assert.deepEqual(ids, ['adal']);
});
+test('~/.grok lights up the grok host', () => {
+ const home = fresh(); const repo = fresh();
+ mkdirSync(join(home, '.grok'));
+ const ids = detectHosts(probeFor(home, repo)).map((h) => h.id).sort();
+ assert.deepEqual(ids, ['grok']);
+});
+
+test('repo-local .grok also lights up the grok host', () => {
+ const home = fresh(); const repo = fresh();
+ mkdirSync(join(repo, '.grok'));
+ const ids = detectHosts(probeFor(home, repo)).map((h) => h.id).sort();
+ assert.deepEqual(ids, ['grok']);
+});
+
test('~/.hermes or AppData/Local/hermes lights up the hermes host', () => {
const home = fresh(); const repo = fresh();
mkdirSync(join(home, 'AppData', 'Local', 'hermes'), { recursive: true });