The Hooks tab said "Grok App has no hooks magpie can write" and RTK said
"No rtk hook". RTK stays correct for now (rtk init has no Grok agent), but
the hooks message was wrong: the Grok CLI keeps hooks as [[hooks.<Event>]]
array tables in its config.toml, which Grok App reads from agent-home on a
custom route. Hindsight already ships three hooks into both configs.
Add grok and grok-app to hookAgents with a TOML hook spec. A hook is written
as a [[hooks.<Event>]] table with a [[hooks.<Event>.hooks]] child, the same
find/claim/drop logic as a JSON agent's: the block text is recorded entry by
entry, so only a block still exactly as magpie wrote it is ever taken out,
and the user's own blocks around it stay as they are. Portable events map to
Stop / PostToolUse / PreToolUse / UserPromptSubmit / SessionStart; a tool
matcher uses Grok's own tool names (run_terminal_command, search_replace).
Grok Build and Grok App run the one CLI, so a grok:<Event> own event goes to
both (sameHookFamily).
edit gains WriteTOMLFile and SplitLines so the library can round-trip a
config's lines through the same validating write the other TOML editors use.
Verification (branch grokapp-hooks):
- TestHooksGrokConfigTables fails on the pre-change code with a real FAIL
("Grok Build has no hooks magpie can write"); passes with the change.
Broke the matcher map, the drop and the event map by hand; each break is
caught by the test.
- go test ./internal/library ./internal/edit: 811 passed (was 828 before the
two new grok cases and the hookAgents additions).
- gofmt -l clean; go vet on mac, GOOS=linux -tags nogui, and GOOS=windows all
clean; go build, GOOS=linux go build -tags nogui and GOOS=windows go build
all succeed.
- go test -tags nogui ./... has three pre-existing failures on base cdb7b5ff
(internal/gateway TestGrokCallsGiveCodexIntegers, internal/library
TestRTKCheckLatestDoesNotWaitForThePackageManager, internal/proc
TestNoCommandBypassesProc); none is in a file this change touches, and each
reproduces without it.
- Real use: confirmed against the local Grok App 0.2.40 / grok 1.0.55 install
that agent-home/config.toml already carries Hindsight's [[hooks.*]] tables,
so the shape matches what magpie now writes. The GUI Hooks tab is driven by
the backend hookAgents view, which now lists grok and grok-app; the Tauri
window itself was not clicked through.
Reviewed before landing (fu13-pt, on e297a8ab2 + #1889/#1897/#1900/#1989):
- The shape is Grok's own: grok 1.0.50's binary carries its user guide
(10-hooks.md), which reads hooks from ~/.grok/config.toml as
[[hooks.<Event>]] with an optional matcher and an inner hooks array,
the [[hooks.<Event>.hooks]] form accepted; handler fields type, command,
url, timeout, env; run_terminal_command and search_replace are its tool
names (Bash and Edit|Write|MultiEdit are aliases of them).
- A scratch test (not committed) on a config holding a user's inline
`hooks = [ {...} ]` Stop block, a comment, [mcp_servers.x], a user
PreToolUse block and [ui]: add (Stop, PreToolUse on shell), edit the
timeout, remove both. The file parsed as TOML at each step with the
arrays as Grok reads them, and came back byte for byte. A config with a
plain [hooks] table (Stop = [...]) is refused as a problem ("key value
already exists as a Stop, but should be an array table"), file unchanged.
- Drop broken by hand (never drops a block): TestHooksGrokConfigTables and
TestHooksGrokOwnEventBoth both FAIL with the blocks left; restored, pass.
- Not tried: the Grok App window, and a running grok reading the result.
Grok App in shared mode reads ~/.grok, not agent-home, as its MCP row
already does.