Commit Graph
5 Commits
Author SHA1 Message Date
yetone 6f87624dbf library: the three Windows-red tests write Hermes and Codex fixtures where those apps do, not the Unix layout (#2275)
All three were test fixtures, not magpie writing a bad file.

TestHooksCodexTrustMovesWithTheGroups wrote Codex's [hooks.state."<path>"]
keys itself as basic strings, so on Windows "C:\Users\..." held \U, and
toml read the test's own file as broken ("toml: non-hex character").
Codex doesn't write that. Driving the real `codex app-server`
(0.162.1, config/batchWrite on hooks.state, as its /hooks does) under a
sandbox CODEX_HOME shows its toml_writer spelling: a basic string when
nothing needs escaping, a literal string ('C:\Users\x\...') when a
backslash does, and an escaped basic string ("C:\\Users\\O'Brien\\...")
when the key has an apostrophe too, under a bare [hooks.state] header.
codexKey in the test now spells keys that way, and the test runs for
the default home, a CODEX_HOME with a backslash in it and one with an
apostrophe as well, so macOS and Linux exercise both quoted forms too.
codexRekey already reads both and rewrites only the key's tail, so the
spelling is kept.

Every place magpie writes a path into TOML was checked: edit.tomlString
(every edit.KV string value, model_catalog_json among them),
library/mcp.go tomlString/tomlKey, provider/devin.go tomlString all
escape backslashes; the strconv.Quote writers (grok/kimi/atomcode/jcode/
reasonix/codex reasoning efforts, Grok hook blocks) write model ids,
efforts and commands, where a backslash comes out as \\ too. None writes
an unescaped path, so no writer changes.

TestAgentsSkillsFolders and TestTargetsLeaveGoneAgentsOut wrote Hermes's
config.yaml into ~/.hermes, but Hermes's folder on Windows is
%LOCALAPPDATA%\hermes (appdir.HermesHome). There Hermes wasn't there at
all: its skills folder was the Windows one, and Takes for an agent with
no folder says yes rather than "isn't installed". Both now write into
appdir.HermesHome(), and TestTargetsLeaveGoneAgentsOut first checks
Hermes is detected by that config, so a fixture in the wrong place fails
as that rather than as a Takes result.

Run:
- Windows 11 box, test binaries cross-built (GOOS=windows -tags nogui),
  fresh USERPROFILE/HOME/APPDATA/LOCALAPPDATA/TEMP each run, cwd with
  internal/library/testdata:
  - origin/main 2b0037f41: the three fail as in the issue.
  - this change: the whole internal/library package PASS.
  - this change with codexRekey's literal-key branch disabled by hand:
    TestHooksCodexTrustMovesWithTheGroups/default and /backslash FAIL
    ("keeps Codex's trust of ... in a way magpie can't move").
- macOS: the same break fails /backslash; restored, all pass.
- real codex 0.162.1 app-server in a sandbox HOME/CODEX_HOME for the
  three key spellings above.

- macOS, rebased on origin/main 9d97fd073: gofmt -l prints
  nothing; go vet -tags nogui ./internal/library for GOOS=darwin, linux
  and windows ok; go test -p 1 -count=1 ./internal/library ok (132s)
  in a sandbox HOME/TMPDIR with Go's caches pinned.
- Full suite: SUITE_LINE
2026-10-15 23:08:03 +08:00
fjrtdk 8f34bbcd11 library: Grok Build and Grok App can be given hooks (#1790)
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.
2026-10-14 05:43:48 +08:00
yetone 45e77b61f7 library: Claude Code's hooks can go on every event it has, StopFailure, PostCompact and FileChanged among them (#2020, emo172)
The claude branch of hookSpecOf knew 12 of Claude Code's events, so a
hook on StopFailure, PostCompact, CwdChanged, WorktreeCreate and the
rest was refused ("it has no event called StopFailure") and could only
be written into settings.json by hand, outside magpie's record and
backups. The list is now claudeHookEvents: all 33 names of the
HOOK_EVENTS enum in the real claude 2.1.296 binary, read from it with
strings (read only, ~/.claude untouched). That is the 14 the issue
lists plus six it didn't (PostToolBatch, UserPromptExpansion,
PermissionDenied, Elicitation, ElicitationResult, DirectoryAdded). The
page's event picker takes the agent's list from the same table, so it
offers them too. Codex's, Gemini's and Cursor's tables are not
changed here: each of Codex's 12 names is in codex 0.162.1's strings,
but its full enum wasn't extracted.

Run: go test ./internal/library (TestHooksClaudeEventsAll new; on the
old table it fails with "it has no event called StopFailure"), gofmt
-l, GOOS=linux and GOOS=windows go vet -tags nogui ./internal/library.
2026-10-14 05:22:46 +08:00
yetone 17d4283a5a library, gui: a hook has a description in any language, shown under its name (#2011, emo172)
A hook's name is letters, digits, - and _ (checkName), so a Chinese user
had to translate "auto-format-queue" back in their head; 编辑后格式化 was
refused. Hook now has an optional Description: one line (whitespace and
line breaks folded into single spaces) of at most 200 characters, kept
in library.json only and never written into an agent's hooks file. The
Hooks tab shows it under the name; the editor has a Description field
(maxlength 200) under Name. The library's text fields no longer save or
close on an Enter or Escape that only ends an input method's composition
(isComposing / keyCode 229), which a Chinese description would hit.
Strings in zh, zh-TW, ja and de; docs/subsystems/library.md says it.

The reporter's other option, non-ASCII names, wasn't taken: the
description says more than a name can, and names stay one rule across
servers, skills and hooks.

Run: TestHookDescription (kept through a save, an agents change and a
rename, read by the page, no agent file has it, 201 characters refused,
200 kept) fails with the folding and the length check removed.
library-hooks.test.cjs (a description under the name, none for a hook
without, the field's placeholder and hint, an IME Enter posts nothing,
Save posts the description) fails on the old library.js and with the IME
guard removed. library-*, gui-de, gui-ja, gui-zh-tw, i18n-keys and
click-scroll pass in Chromium and WebKit (263/263 each). go test -tags
nogui ./internal/library ./internal/gui under a temp HOME, gofmt -l,
GOOS=linux and GOOS=windows go vet -tags nogui ./internal/library pass.
2026-10-14 04:18:36 +08:00
yetone e3a497d7a2 library, gui: Hooks are a fifth Library category, kept once and written into each ticked agent's own hooks file (#1790, AllenReder)
What: the Library page has a Hooks tab beside Instructions, MCP, Skills
and RTK. A hook is a command, an event, an optional tool filter, a
timeout and the agents ticked for it. magpie writes it into each agent in
that agent's own file and shape:
  Claude Code  <claude dir>/settings.json   hooks.<Event>[{matcher, hooks[]}]
  Codex        <codex home>/hooks.json       same shape
  Gemini CLI   ~/.gemini/settings.json       same shape, timeout in ms
  Cursor       ~/.cursor/hooks.json          flat entries, version 1
Portable events (turn end, after a tool, before a tool, prompt sent,
session start) map to each agent's own name; "shell"/"edit" map to each
agent's own tool names. An agent's own event (codex:PermissionRequest,
cursor:afterFileEdit, ...) is offered too and given to that agent only.
Rows have agent chips (All first), Select + bar, and Remove all, like
skills and servers. An agent that can't take a hook has its chip greyed
with the reason: every agent but those four ("has no hooks magpie can
write"), an agent in WSL (not yet), and another agent for a native event.
The page also says when an agent has all hooks turned off
(disableAllHooks, hooksConfig.enabled=false, [features] hooks=false).

Why these choices (product call delegated to us): the four agents are
the ones with a documented, file-based command-hook API whose events line
up; others (OpenCode's JS plugins, dsh, ...) have no comparable file, so
they're named as unavailable rather than half-supported. Removal is
exact: Applied.Hooks records each entry as written (canonical JSON), and
only an entry still exactly as written is taken out; one the user edited
is theirs, and their own hooks beside it are never touched. A hooks file
that doesn't parse is a problem, never treated as empty or written over.
Codex keeps trust per hook in config.toml keyed by group position, so
taking a group out re-keys the user's trust for the groups after it
(codexRekey) instead of silently untrusting them. Carried bundles
(backup/WebDAV/S3) don't carry hooks in this first version.

Run:
- go test ./internal/library ./internal/gui (sandbox HOME): pass. New
  hooks_test.go: each agent's shape; the user's edited entry stays and is
  no longer recorded; an unparseable file is left alone and reported;
  Codex trust moves with its groups; native events/unavailable agents;
  hooks-off reported.
- library-hooks.test.cjs: 12/12 in chromium and webkit, at 440px, in en,
  zh, zh-TW, ja, de; against the old library.js it fails (timeouts on the
  missing tab). All 52 new strings translated in the 4 languages.
- library-loading.test.cjs expects the Hooks tab in its tab lists
  (it failed on this change before; 6/6 now).
- Every library-*/skill-* GUI test in chromium and webkit: all pass but
  WebKit timeouts in library-mcp-tool-switch/library-mcp-tools, which fail
  the same on origin/main b0a904bd9 under load (#1609, commented).
- gofmt -l, go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: clean. Full go test ./... at the pre-rebase
  head c1c1a730f: 49 packages ok. After rebasing onto 86b2f4d05:
  library, gui and gateway's Anthropic/Zed tests ok.

Not tried: real Claude Code / Codex / Gemini / Cursor runs firing the
written hooks; the shapes were checked against each agent's source and
docs, not executed.
2026-10-12 22:44:28 +08:00