You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@magpie.apache.org by "KatalKavya96 (via GitHub)" <gi...@apache.org> on 2026/10/05 06:39:32 UTC
[PR] feat(agent-guard): add Grok PreToolUse integration [magpie]
KatalKavya96 opened a new pull request, #1516:
URL: https://github.com/apache/magpie/pull/1516
## Summary
Adds native Grok `PreToolUse` support to `tools/agent-guard` while keeping the guard engine harness-neutral.
The new Grok adapter translates Grok hook input into the existing shared `dispatch(command, cwd)` path and returns Grok-compatible allow/deny decisions.
Refs #1416
## What changed
- Added `--grok` support to `agent-guard`
- Added `grok_main()` as a thin adapter around the shared guard dispatcher
- Added `.grok/hooks/magpie-agent-guard.json`
- Handles Grok shell tools:
- `run_terminal_command`
- `run_terminal_cmd`
- Returns explicit Grok decisions:
- `{"decision": "allow"}`
- `{"decision": "deny", "reason": "..."}`
- Added unit and end-to-end tests for:
- allow / deny behavior
- shell-tool aliases
- `cwd` forwarding
- malformed and irrelevant events
- explicit `--grok` routing
- preserving the default Claude Code invocation
- execution through the committed Grok hook
## Setup lifecycle
Added Grok hook handling to setup install, upgrade, and uninstall flows.
Magpie owns only:
```text
.grok/hooks/magpie-agent-guard.json
```
The lifecycle intentionally does not modify:
- unrelated `.grok/hooks/*`
- `.grok/config.toml`
- Grok project-hook trust state
Hook trust remains an explicit operator decision.
Snapshot adopters derive their hook from the committed Magpie hook and only change the executable path to the `.apache-magpie` snapshot.
## Metadata and documentation
- Added Grok to `agent-guard` harness metadata
- Added Grok to the vendor-neutrality harness vocabulary
- Regenerated vendor-neutrality documentation
- Updated the adapter registry from `reviewer backend only` to `reviewer backend + action guard`
- Added the strict JSON hook file to `.rat-excludes`
- Regenerated the setup-preflight fingerprint
This PR intentionally does **not** add full Grok `spec-loop` / headless harness support. That remains separate work under #1416.
## Validation
Validated with:
- `tools/agent-guard`: 199 tests passing
- `tools/vendor-neutrality-score`: 36 tests passing
- Ruff check and format
- mypy
- full workspace pytest
- Markdown / link / placeholder checks
- setup fingerprint checks
- symlink and release archive checks
- skill and tool validation
- spec validation
- full `prek run --all-files`
On macOS, the full workspace gate was run with `TMPDIR=/tmp` to avoid the pre-existing `container-gateway` AF_UNIX socket path-length issue.
## AI assistance
AI assistance was used for implementation planning, repository analysis, patch review, and test/debug iteration. All changes were reviewed and validated locally before submission.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@magpie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(agent-guard): add Grok PreToolUse integration [magpie]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk merged PR #1516:
URL: https://github.com/apache/magpie/pull/1516
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@magpie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(agent-guard): add Grok PreToolUse integration [magpie]
Posted by "KatalKavya96 (via GitHub)" <gi...@apache.org>.
KatalKavya96 commented on PR #1516:
URL: https://github.com/apache/magpie/pull/1516#issuecomment-6095099550
@potiuk Addressed the remaining review items in 5bff83a66.
- Removed the duplicate active Grok project hook from this repository and kept the project-hook shape as an inactive setup template. `grok inspect --json` now shows a single active Magpie action-guard hook from the enabled plugin.
- Live-verified the rebuilt shared plugin on Claude Code 2.1.287: `git commit --no-verify --dry-run` was blocked during `PreToolUse:Bash` by `agent-guard[no-verify]`.
- Replaced `GROK_HOOK_EVENT`-based no-argument routing with payload-shape routing, including regression coverage that an inherited Grok env var cannot misroute a Claude payload.
- Fixed the adapter wording and duplicate SPDX nit.
- Regenerated the packaged runtime and isolated setup fingerprint.
Full `TMPDIR=/tmp prek run --all-files` is green.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@magpie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(agent-guard): add Grok PreToolUse integration [magpie]
Posted by "KatalKavya96 (via GitHub)" <gi...@apache.org>.
KatalKavya96 commented on PR #1516:
URL: https://github.com/apache/magpie/pull/1516#issuecomment-6092965155
@potiuk Addressed the remaining review concerns.
For the marketplace/plugin path, magpie-agent-guard now registers through hooks/hooks.json and packages the guard runtime as real files inside the plugin instead of relying on the escaping symlink. I verified this on Grok Build 1.0.50: the plugin reports provides.hooks: true, the installed runtime resolves correctly, /hooks shows the active hook, and git commit --no-verify --dry-run is blocked by the actual Magpie agent-guard[no-verify] policy.
I also rechecked the failure semantics. A bare PreToolUse hook that exits 2 with no JSON blocks the shell tool call on Grok 1.0.50, and a missing Python hook target that exits 2 is blocked as well. The docs now distinguish that from malformed/unrelated input handled inside grok_main(), which deliberately returns 0 and remains fail-open.
I kept the original payload provenance separate: the captured run_terminal_command payload is from Grok Build 1.0.46, while marketplace loading, packaged-runtime execution, real policy denial, and exit-2 behavior were verified on 1.0.50.
Full prek run --all-files is green after the changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@magpie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(agent-guard): add Grok PreToolUse integration [magpie]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on code in PR #1516:
URL: https://github.com/apache/magpie/pull/1516#discussion_r4181712433
##########
tools/agent-guard/src/agent_guard/__init__.py:
##########
@@ -924,6 +927,43 @@ def gemini_main() -> int:
return ALLOW_EXIT
+def grok_main() -> int:
+ """Translate Grok Build's ``PreToolUse`` event to the shared guard core.
+
+ Grok sends camelCase hook fields (``toolName`` / ``toolInput``) and its
+ shell tool is currently exposed as ``run_terminal_command`` (with
+ ``run_terminal_cmd`` retained as an internal/compatibility spelling).
+ An explicit JSON decision is written for relevant shell calls: allow exits
+ 0, deny exits 2 with the shared guard reason. Malformed and irrelevant
+ events remain silent and fail open.
+ """
+ try:
+ event = json.load(sys.stdin)
+ except (json.JSONDecodeError, ValueError):
+ return ALLOW_EXIT
+ if not isinstance(event, dict):
+ return ALLOW_EXIT
+ if event.get("toolName") not in ("run_terminal_command", "run_terminal_cmd"):
Review Comment:
**major** — This adapter only fires if Grok really sends camelCase `toolName`/`toolInput` and really names its shell tool `run_terminal_command`/`run_terminal_cmd` — and nothing in the PR or the repo sources either assumption (no Grok hook-API link, no `docs/adapters/grok.md`). On any mismatch it fails open silently: the guard allows every command with no output, which is the worst failure mode a security hook can have, and the end-to-end test can't catch it because it feeds a hand-written payload to a hand-written adapter. Please (1) link Grok's hook-API docs for the event name, input fields, the shell tool name(s) the matcher sees, and the output/exit-code contract — ideally in a short `docs/adapters/grok.md` like `gemini.md`; (2) replace the fixture with a payload captured from a real Grok session, noting the Grok version; (3) state that version in the README.
##########
tools/agent-guard/src/agent_guard/__init__.py:
##########
@@ -924,6 +927,43 @@ def gemini_main() -> int:
return ALLOW_EXIT
+def grok_main() -> int:
+ """Translate Grok Build's ``PreToolUse`` event to the shared guard core.
+
+ Grok sends camelCase hook fields (``toolName`` / ``toolInput``) and its
+ shell tool is currently exposed as ``run_terminal_command`` (with
+ ``run_terminal_cmd`` retained as an internal/compatibility spelling).
+ An explicit JSON decision is written for relevant shell calls: allow exits
+ 0, deny exits 2 with the shared guard reason. Malformed and irrelevant
+ events remain silent and fail open.
+ """
+ try:
+ event = json.load(sys.stdin)
+ except (json.JSONDecodeError, ValueError):
+ return ALLOW_EXIT
+ if not isinstance(event, dict):
+ return ALLOW_EXIT
+ if event.get("toolName") not in ("run_terminal_command", "run_terminal_cmd"):
+ return ALLOW_EXIT
+ tool_input = event.get("toolInput")
+ if not isinstance(tool_input, dict):
+ return ALLOW_EXIT
+ command = tool_input.get("command")
+ if not isinstance(command, str):
+ return ALLOW_EXIT
+
+ cwd = event.get("cwd")
+ reason = dispatch(command, cwd if isinstance(cwd, str) else None)
+ if reason:
+ json.dump({"decision": "deny", "reason": reason}, sys.stdout)
Review Comment:
**minor** — On deny, the reason goes only to stdout with exit 2. Under the Claude-style convention the Kiro and Gemini adapters follow, exit 2 means "block, and stderr is the reason" — stdout is ignored, so the model would be blocked without being told why and keep retrying variants. Unless Grok's docs say exit 2 + stdout JSON is the intended combination, also write the reason to stderr on deny (works under either reading), and cite the doc section that defines the semantics.
##########
tools/agent-guard/tests/test_grok.py:
##########
@@ -0,0 +1,254 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Tests for Grok Build's PreToolUse adapter."""
+
+from __future__ import annotations
+
+import io
+import json
+import os
+import subprocess
+from pathlib import Path
+
+import pytest
+
+import agent_guard
+
+
+def _feed(monkeypatch: pytest.MonkeyPatch, payload: object) -> None:
+ text = payload if isinstance(payload, str) else json.dumps(payload)
+ monkeypatch.setattr("sys.stdin", io.StringIO(text))
+
+
+def _event(
+ command: str,
+ *,
+ tool_name: str = "run_terminal_command",
+ cwd: object = ".",
+) -> dict[str, object]:
+ return {
+ "hookEventName": "pre_tool_use",
Review Comment:
**minor** — `_event()` sets both `hookEventName: "pre_tool_use"` and `hook_event_name: "PreToolUse"`, and the adapter reads neither, so these tests pass whatever Grok actually sends. Please use one verbatim captured `PreToolUse` payload from a real Grok session, with its source noted, so the fixture is evidence of the format rather than an assumption.
##########
plugins/magpie-setup/skills/setup/install.md:
##########
@@ -1913,6 +1913,24 @@ Four passes, in this order:
Follow [the Gemini install lifecycle](../../../../docs/adapters/gemini.md#install) to propose and merge its workspace profile and guard registration from this snapshot.
Preserve unrelated configuration and review conflicts before applying changes.
Validate the merged profile and hand off live verification to Gemini.
+ **Grok project guard (when Grok is the selected runtime).**
+ Install exactly one Magpie-owned project hook at
Review Comment:
**nit** — `AGENTS.md` asks for semantic line breaks — "one sentence per line". The Gemini block just above follows it; please reflow the Grok blocks here, in `upgrade.md`, `uninstall.md`, and the README `### Grok` section the same way.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@magpie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(agent-guard): add Grok PreToolUse integration [magpie]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on code in PR #1516:
URL: https://github.com/apache/magpie/pull/1516#discussion_r4236660799
##########
docs/adapters/grok.md:
##########
@@ -0,0 +1,185 @@
+<!-- SPDX-License-Identifier: Apache-2.0
+ https://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!-- START doctoc generated TOC please keep comment here to allow auto update -->
+<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
+**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
+
+- [Grok Build](#grok-build)
+ - [Harness contract](#harness-contract)
+ - [Verified runtime](#verified-runtime)
+ - [Installation](#installation)
+ - [Marketplace plugin](#marketplace-plugin)
+ - [Framework checkout](#framework-checkout)
+ - [Pinned snapshot](#pinned-snapshot)
+ - [Trust and security boundary](#trust-and-security-boundary)
+ - [Guard behavior](#guard-behavior)
+ - [Verify](#verify)
+ - [Update and uninstall](#update-and-uninstall)
+ - [Known limitations](#known-limitations)
+ - [Developer checks](#developer-checks)
+ - [Upstream references](#upstream-references)
+
+<!-- END doctoc generated TOC please keep comment here to allow auto update -->
+
+<!-- SPDX-License-Identifier: Apache-2.0 -->
+
+# Grok Build
+
+**Capability:** platform:harness
+
+Grok Build is supported in this PR for the deterministic Magpie action guard.
Review Comment:
"Supported in this PR" describes the PR, not the adapter, and won't read right once merged. Something like "Grok Build is supported for the deterministic Magpie action guard."
##########
docs/adapters/grok.md:
##########
@@ -0,0 +1,185 @@
+<!-- SPDX-License-Identifier: Apache-2.0
+ https://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!-- START doctoc generated TOC please keep comment here to allow auto update -->
+<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
+**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
+
+- [Grok Build](#grok-build)
+ - [Harness contract](#harness-contract)
+ - [Verified runtime](#verified-runtime)
+ - [Installation](#installation)
+ - [Marketplace plugin](#marketplace-plugin)
+ - [Framework checkout](#framework-checkout)
+ - [Pinned snapshot](#pinned-snapshot)
+ - [Trust and security boundary](#trust-and-security-boundary)
+ - [Guard behavior](#guard-behavior)
+ - [Verify](#verify)
+ - [Update and uninstall](#update-and-uninstall)
+ - [Known limitations](#known-limitations)
+ - [Developer checks](#developer-checks)
+ - [Upstream references](#upstream-references)
+
+<!-- END doctoc generated TOC please keep comment here to allow auto update -->
+
+<!-- SPDX-License-Identifier: Apache-2.0 -->
Review Comment:
Duplicate SPDX comment; the file already opens with one on line 1.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@magpie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(agent-guard): add Grok PreToolUse integration [magpie]
Posted by "KatalKavya96 (via GitHub)" <gi...@apache.org>.
KatalKavya96 commented on PR #1516:
URL: https://github.com/apache/magpie/pull/1516#issuecomment-6065799352
@potiuk Thanks for the review — I’ve pushed the follow-up changes in `59eab13`.
The Grok guard is now based on the documented and observed hook contract rather than assumptions:
- switched the hook matcher to the documented `Bash` matcher
- verified against Grok Build `1.0.46 (2765805b9442)`
- captured a real `PreToolUse` payload from that runtime and use it verbatim in the regression test
- removed the speculative `run_terminal_cmd` alias; the observed concrete shell tool is `run_terminal_command`
- documented the Grok contract, version, trust boundary, lifecycle, marketplace behavior, and fail-open behavior in `docs/adapters/grok.md`
- aligned allow/deny handling with the documented semantics: silent exit `0` for allow and JSON deny reason + exit `2` for denial
- added `--grok` to the affected action-guard spec without adding Grok spec-loop/headless/sandbox support
- documented how marketplace installs use the existing Claude-compatible `magpie-agent-guard` plugin directly, while source/snapshot installs use the project hook
- documented that a broken/missing launcher fails open, so verification requires a real live denial
- reflowed the Grok documentation blocks to semantic line breaks
- rebased and regenerated the vendor-neutrality output, setup fingerprint, and generated skill metadata
I also tested it live in Grok:
- `grok inspect --json` showed the trusted project `PreToolUse` hook with matcher `Bash`
- `pwd` was allowed
- `git commit --no-verify --dry-run` was blocked by the agent guard before execution
The full local `prek` suite and focused agent-guard tests are green. CI is currently running on the updated branch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@magpie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(agent-guard): add Grok PreToolUse integration [magpie]
Posted by "KatalKavya96 (via GitHub)" <gi...@apache.org>.
KatalKavya96 commented on PR #1516:
URL: https://github.com/apache/magpie/pull/1516#issuecomment-5989449801
Hi @potiuk, I’ve opened the next piece of #1416 for the Grok integration.
This PR adds native Grok `PreToolUse` support to `agent-guard`, keeps the shared guard logic harness-neutral, wires the project hook/setup lifecycle, and adds end-to-end coverage for the committed hook.
I’ve intentionally kept full Grok `spec-loop` / headless harness support out of this PR so the changes stay incremental and reviewable.
Would appreciate your review when you get a chance.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@magpie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(agent-guard): add Grok PreToolUse integration [magpie]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on code in PR #1516:
URL: https://github.com/apache/magpie/pull/1516#discussion_r4232185618
##########
docs/adapters/grok.md:
##########
@@ -0,0 +1,166 @@
+<!-- SPDX-License-Identifier: Apache-2.0
+ https://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!-- START doctoc generated TOC please keep comment here to allow auto update -->
+<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
+**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
+
+- [Grok Build](#grok-build)
+ - [Harness contract](#harness-contract)
+ - [Verified runtime](#verified-runtime)
+ - [Installation](#installation)
+ - [Marketplace plugin](#marketplace-plugin)
+ - [Framework checkout](#framework-checkout)
+ - [Pinned snapshot](#pinned-snapshot)
+ - [Trust and security boundary](#trust-and-security-boundary)
+ - [Guard behavior](#guard-behavior)
+ - [Verify](#verify)
+ - [Update and uninstall](#update-and-uninstall)
+ - [Known limitations](#known-limitations)
+ - [Developer checks](#developer-checks)
+ - [Upstream references](#upstream-references)
+
+<!-- END doctoc generated TOC please keep comment here to allow auto update -->
+
+<!-- SPDX-License-Identifier: Apache-2.0 -->
+
+# Grok Build
+
+**Capability:** platform:harness
+
+Grok Build is supported in this PR for the deterministic Magpie action guard.
+This does not add Grok spec-loop, headless-runner, or dedicated sandbox-profile support.
+
+## Harness contract
+
+| Surface | Grok contract | Magpie integration |
+|---|---|---|
+| Hook event | `PreToolUse` | `agent-guard` |
+| Shell matcher | `Bash` | `.grok/hooks/magpie-agent-guard.json` or plugin hook |
+| Captured shell tool | `run_terminal_command` | reads `toolInput.command` |
+| Workspace path | `GROK_WORKSPACE_ROOT` | source/snapshot project hook |
+| Plugin path | `GROK_PLUGIN_ROOT` | marketplace/plugin hook |
+| Deny | JSON decision with reason | shared `dispatch()` result |
+| Allow | exit 0 | shared `dispatch()` result |
+
+## Verified runtime
+
+The adapter was verified against:
+
+`grok 1.0.46 (2765805b9442)`
+
+A real `PreToolUse` payload captured on 2026-10-08 is retained in
+`tools/agent-guard/tests/test_grok.py`.
+The capture was triggered by asking Grok to run `pwd`.
+The captured event reported `toolName: "run_terminal_command"` and placed the
+shell command in `toolInput.command`.
+
+## Installation
+
+### Marketplace plugin
+
+Grok reads Claude-compatible marketplaces, plugins, and hooks without extra compatibility setup.
+When the existing `magpie-agent-guard` marketplace plugin runs under Grok,
+Grok supplies `GROK_HOOK_EVENT`.
+The no-argument dispatcher detects that variable and selects `grok_main()`.
Review Comment:
The plugin hook uses `${CLAUDE_PLUGIN_ROOT}`, but Grok documents only `GROK_PLUGIN_ROOT`. Please verify a live denial on a marketplace install, or add the `${CLAUDE_PLUGIN_ROOT:-$GROK_PLUGIN_ROOT}` fallback.
##########
docs/adapters/grok.md:
##########
@@ -0,0 +1,166 @@
+<!-- SPDX-License-Identifier: Apache-2.0
+ https://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!-- START doctoc generated TOC please keep comment here to allow auto update -->
+<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
+**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
+
+- [Grok Build](#grok-build)
+ - [Harness contract](#harness-contract)
+ - [Verified runtime](#verified-runtime)
+ - [Installation](#installation)
+ - [Marketplace plugin](#marketplace-plugin)
+ - [Framework checkout](#framework-checkout)
+ - [Pinned snapshot](#pinned-snapshot)
+ - [Trust and security boundary](#trust-and-security-boundary)
+ - [Guard behavior](#guard-behavior)
+ - [Verify](#verify)
+ - [Update and uninstall](#update-and-uninstall)
+ - [Known limitations](#known-limitations)
+ - [Developer checks](#developer-checks)
+ - [Upstream references](#upstream-references)
+
+<!-- END doctoc generated TOC please keep comment here to allow auto update -->
+
+<!-- SPDX-License-Identifier: Apache-2.0 -->
+
+# Grok Build
+
+**Capability:** platform:harness
+
+Grok Build is supported in this PR for the deterministic Magpie action guard.
+This does not add Grok spec-loop, headless-runner, or dedicated sandbox-profile support.
+
+## Harness contract
+
+| Surface | Grok contract | Magpie integration |
+|---|---|---|
+| Hook event | `PreToolUse` | `agent-guard` |
+| Shell matcher | `Bash` | `.grok/hooks/magpie-agent-guard.json` or plugin hook |
+| Captured shell tool | `run_terminal_command` | reads `toolInput.command` |
+| Workspace path | `GROK_WORKSPACE_ROOT` | source/snapshot project hook |
+| Plugin path | `GROK_PLUGIN_ROOT` | marketplace/plugin hook |
+| Deny | JSON decision with reason | shared `dispatch()` result |
+| Allow | exit 0 | shared `dispatch()` result |
+
+## Verified runtime
+
+The adapter was verified against:
+
+`grok 1.0.46 (2765805b9442)`
+
+A real `PreToolUse` payload captured on 2026-10-08 is retained in
+`tools/agent-guard/tests/test_grok.py`.
+The capture was triggered by asking Grok to run `pwd`.
+The captured event reported `toolName: "run_terminal_command"` and placed the
+shell command in `toolInput.command`.
+
+## Installation
+
+### Marketplace plugin
+
+Grok reads Claude-compatible marketplaces, plugins, and hooks without extra compatibility setup.
+When the existing `magpie-agent-guard` marketplace plugin runs under Grok,
+Grok supplies `GROK_HOOK_EVENT`.
+The no-argument dispatcher detects that variable and selects `grok_main()`.
+The executable therefore remains inside the installed substrate plugin rather
+than requiring an `.apache-magpie/` snapshot only to reach the guard.
+
+### Framework checkout
+
+The repository hook is:
+
+`.grok/hooks/magpie-agent-guard.json`
+
+It resolves the guard through `GROK_WORKSPACE_ROOT` and invokes `--grok`.
+
+### Pinned snapshot
+
+A snapshot adopter may install the same single Magpie-owned project hook.
+Its executable path points through
+`$GROK_WORKSPACE_ROOT/.apache-magpie/tools/agent-guard/`.
+
+Magpie owns only that exact hook file.
+It does not own `.grok/hooks/`, `.grok/config.toml`, unrelated hooks, or project trust.
+
+## Trust and security boundary
+
+Project `.grok/hooks/` entries require an explicit Grok trust decision.
+Magpie must never grant or reset that trust on the operator's behalf.
+
+The action guard is separate from Grok permissions and from the operating-system sandbox.
+It inspects shell commands before execution and rejects commands that violate a
+hard Magpie framework rule.
+It does not turn native file tools, MCP tools, or the rest of the process into a sandbox.
+
+## Guard behavior
+
+For a relevant `run_terminal_command` event, the adapter passes the command and
+optional string `cwd` to the harness-neutral `dispatch()` core.
+
+A denial emits a Grok deny decision containing the shared guard reason and exits
+with the guard deny code.
+An allowed shell command exits 0 without emitting a decision.
+
+Malformed input, unrelated tools, or an invalid command field are ignored and
+fail open.
+A missing or broken hook executable likewise does not provide protection, so
Review Comment:
`python3` exits 2 on a missing script, and Grok reads exit 2 as a deny. Please document what Grok actually does here.
##########
docs/adapters/grok.md:
##########
@@ -0,0 +1,166 @@
+<!-- SPDX-License-Identifier: Apache-2.0
+ https://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!-- START doctoc generated TOC please keep comment here to allow auto update -->
+<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
+**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
+
+- [Grok Build](#grok-build)
+ - [Harness contract](#harness-contract)
+ - [Verified runtime](#verified-runtime)
+ - [Installation](#installation)
+ - [Marketplace plugin](#marketplace-plugin)
+ - [Framework checkout](#framework-checkout)
+ - [Pinned snapshot](#pinned-snapshot)
+ - [Trust and security boundary](#trust-and-security-boundary)
+ - [Guard behavior](#guard-behavior)
+ - [Verify](#verify)
+ - [Update and uninstall](#update-and-uninstall)
+ - [Known limitations](#known-limitations)
+ - [Developer checks](#developer-checks)
+ - [Upstream references](#upstream-references)
+
+<!-- END doctoc generated TOC please keep comment here to allow auto update -->
+
+<!-- SPDX-License-Identifier: Apache-2.0 -->
+
+# Grok Build
+
+**Capability:** platform:harness
+
+Grok Build is supported in this PR for the deterministic Magpie action guard.
+This does not add Grok spec-loop, headless-runner, or dedicated sandbox-profile support.
+
+## Harness contract
+
+| Surface | Grok contract | Magpie integration |
+|---|---|---|
+| Hook event | `PreToolUse` | `agent-guard` |
+| Shell matcher | `Bash` | `.grok/hooks/magpie-agent-guard.json` or plugin hook |
+| Captured shell tool | `run_terminal_command` | reads `toolInput.command` |
+| Workspace path | `GROK_WORKSPACE_ROOT` | source/snapshot project hook |
+| Plugin path | `GROK_PLUGIN_ROOT` | marketplace/plugin hook |
+| Deny | JSON decision with reason | shared `dispatch()` result |
+| Allow | exit 0 | shared `dispatch()` result |
+
+## Verified runtime
+
+The adapter was verified against:
+
+`grok 1.0.46 (2765805b9442)`
+
+A real `PreToolUse` payload captured on 2026-10-08 is retained in
+`tools/agent-guard/tests/test_grok.py`.
+The capture was triggered by asking Grok to run `pwd`.
+The captured event reported `toolName: "run_terminal_command"` and placed the
+shell command in `toolInput.command`.
+
+## Installation
+
+### Marketplace plugin
+
+Grok reads Claude-compatible marketplaces, plugins, and hooks without extra compatibility setup.
+When the existing `magpie-agent-guard` marketplace plugin runs under Grok,
+Grok supplies `GROK_HOOK_EVENT`.
+The no-argument dispatcher detects that variable and selects `grok_main()`.
+The executable therefore remains inside the installed substrate plugin rather
+than requiring an `.apache-magpie/` snapshot only to reach the guard.
+
+### Framework checkout
+
+The repository hook is:
+
+`.grok/hooks/magpie-agent-guard.json`
+
+It resolves the guard through `GROK_WORKSPACE_ROOT` and invokes `--grok`.
+
+### Pinned snapshot
+
+A snapshot adopter may install the same single Magpie-owned project hook.
+Its executable path points through
+`$GROK_WORKSPACE_ROOT/.apache-magpie/tools/agent-guard/`.
+
+Magpie owns only that exact hook file.
+It does not own `.grok/hooks/`, `.grok/config.toml`, unrelated hooks, or project trust.
+
+## Trust and security boundary
+
+Project `.grok/hooks/` entries require an explicit Grok trust decision.
+Magpie must never grant or reset that trust on the operator's behalf.
+
+The action guard is separate from Grok permissions and from the operating-system sandbox.
+It inspects shell commands before execution and rejects commands that violate a
+hard Magpie framework rule.
+It does not turn native file tools, MCP tools, or the rest of the process into a sandbox.
+
+## Guard behavior
+
+For a relevant `run_terminal_command` event, the adapter passes the command and
+optional string `cwd` to the harness-neutral `dispatch()` core.
+
+A denial emits a Grok deny decision containing the shared guard reason and exits
+with the guard deny code.
+An allowed shell command exits 0 without emitting a decision.
+
+Malformed input, unrelated tools, or an invalid command field are ignored and
+fail open.
+A missing or broken hook executable likewise does not provide protection, so
+installation verification must exercise a known allow and a known denial rather
+than treating configuration presence as sufficient.
+
+## Verify
+
+Use:
+
+`grok inspect --json`
+
+Confirm that exactly one intended Magpie action-guard hook is active.
Review Comment:
This repo enables the plugin in `.claude/settings.json`, which Grok also reads, so two Magpie hooks are active.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@magpie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org