Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(hooks): recognize --platform= hooks in shared settings files (#1059)

Rudy Mizrahi Celekli7291792fd8d5
diff --git a/cli/beacon/internal/endpoint/hooks/settings_hooks.go b/cli/beacon/internal/endpoint/hooks/settings_hooks.go
index 68b77bd1..ad37b211 100644
--- a/cli/beacon/internal/endpoint/hooks/settings_hooks.go
+++ b/cli/beacon/internal/endpoint/hooks/settings_hooks.go
@@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"os"
- "strings"
)
// settingsHookGroup and settingsHookRef model the shape Beacon writes into a runtime's shared
@@ -309,7 +308,7 @@ func isSettingsEndpointHookGroup(group settingsHookGroup, platform string) bool
}
func isSettingsEndpointHookCommand(command, platform string) bool {
- if platform != "" && !strings.Contains(command, "--platform "+platform) {
+ if platform != "" && !commandHasPlatform(command, platform) {
return false
}
return isEndpointHookCommand(command, platform)
diff --git a/cli/beacon/internal/endpoint/hooks/settings_hooks_test.go b/cli/beacon/internal/endpoint/hooks/settings_hooks_test.go
index 62fdde8f..2942cc94 100644
--- a/cli/beacon/internal/endpoint/hooks/settings_hooks_test.go
+++ b/cli/beacon/internal/endpoint/hooks/settings_hooks_test.go
@@ -315,6 +315,49 @@ func TestSettingsRuntimesClaimOnlyTheirOwnPlatformsHooks(t *testing.T) {
}
}
+// A hook naming its platform as `--platform=claude` is the same hook as `--platform claude`; the
+// command parser accepts both, so status must see it and uninstall must take it out.
+func TestSettingsRuntimesRecognizeEqualsPlatformFlag(t *testing.T) {
+ for _, tc := range []struct {
+ platform string
+ runtime hookRuntime
+ }{
+ {"claude", claudeRuntime},
+ {"codex", codexRuntime},
+ {"factory", factoryRuntime},
+ {"qwen", qwenRuntime},
+ } {
+ t.Run(tc.platform, func(t *testing.T) {
+ home := t.TempDir()
+ testenv.SetHome(t, home)
+ t.Chdir(t.TempDir())
+ opts := RuntimeOptions{Level: LevelProject, LogPath: filepath.Join(home, "runtime.jsonl"), UserMode: true}
+ path, err := tc.runtime.configPath(LevelProject)
+ if err != nil {
+ t.Fatal(err)
+ }
+ ours := `'/opt/beacon/hooks/beacon-hooks' --platform=` + tc.platform + ` --log '/tmp/runtime.jsonl' pre-tool`
+ seed := `{"hooks":{"PreToolUse":[{"matcher":"*","hooks":[{"type":"command","command":"` + ours + `"}]}]}}`
+ if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(path, []byte(seed), 0o600); err != nil {
+ t.Fatal(err)
+ }
+
+ if !runtimeHookStatus(tc.runtime, opts).Installed {
+ t.Fatalf("status does not see a --platform=%s hook", tc.platform)
+ }
+ if _, err := uninstallRuntimeHooks(tc.runtime, opts); err != nil {
+ t.Fatalf("uninstall: %v", err)
+ }
+ if after := readFile(t, path); strings.Contains(after, ours) {
+ t.Fatalf("uninstall left the --platform=%s hook behind:\n%s", tc.platform, after)
+ }
+ })
+ }
+}
+
// Beacon's own entries are built in code, not read from disk, and must serialize exactly as they
// did before foreign entries were kept verbatim: hook commands are compared by string elsewhere.
func TestSettingsHookRefBuiltInCodeMarshalsKnownFieldsOnly(t *testing.T) {