Skip to content

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

fix(qwen): declare the shell Beacon's hook quoting requires

Justind7f994121dd2
diff --git a/cli/beacon/internal/endpoint/hooks/qwen.go b/cli/beacon/internal/endpoint/hooks/qwen.go
index ff02d541..3a3786dc 100644
--- a/cli/beacon/internal/endpoint/hooks/qwen.go
+++ b/cli/beacon/internal/endpoint/hooks/qwen.go
@@ -35,6 +35,29 @@ const (
// beats "probably equivalent" for the field that decides whether a hook fires at all.
const qwenAllToolsMatcher = "*"
+// qwenHookShell tells Qwen which shell to parse Beacon's hook command with.
+//
+// Beacon builds that command with hookCommandQuote, which single-quotes every path on every
+// platform. Single quotes are fully literal in a POSIX shell, which is what a Windows path needs --
+// inside double quotes bash still expands `$` and eats a doubled backslash, so a profile directory
+// containing a `$` would vanish and a UNC path would lose a separator. That function's own comment
+// records the cost of the choice: the same quoting is not valid in cmd.exe, and in PowerShell a
+// quoted string in command position is an expression rather than a command.
+//
+// Qwen is the runtime that comment anticipated. It runs hook commands through a shell of its
+// choosing and documents exactly two values a hook may ask for, `bash` and `powershell`. Left
+// unset on Windows, a Node-hosted runtime lands on the platform default -- cmd.exe -- where
+// Beacon's quotes are literal characters and every hook fails to start while the install still
+// reports success. That is the same silent-failure shape as writing a seconds-valued timeout, and
+// it is worth the same care.
+//
+// `bash` rather than `powershell` because the command is already POSIX-quoted: choosing the other
+// would mean maintaining a second quoting dialect for one runtime. On macOS and Linux this names
+// the shell that would have run anyway. On Windows it requires bash on PATH, which is the same
+// requirement Claude Code already carries there -- and it strictly improves on the alternative,
+// since cmd.exe cannot parse the command at all.
+const qwenHookShell = "bash"
+
type QwenOptions struct {
Level Level
LogPath string
@@ -106,16 +129,16 @@ func qwenStatusFromRuntime(status runtimeStatus) QwenStatus {
func installQwenSettings(path, binaryPath, logPath, configPath string) error {
prefix := endpointCommandPrefix("qwen", binaryPath, logPath, configPath)
endpointHooks := map[string]settingsHookGroup{
- "SessionStart": {Hooks: []settingsHookRef{{Type: "command", Command: prefix + " session-start"}}},
- "UserPromptSubmit": {Hooks: []settingsHookRef{{Type: "command", Command: prefix + " prompt-submit", Timeout: qwenPromptSubmitTimeoutMS}}},
- "PreToolUse": {Matcher: qwenAllToolsMatcher, Hooks: []settingsHookRef{{Type: "command", Command: prefix + " pre-tool", Timeout: qwenToolTimeoutMS}}},
- "PostToolUse": {Matcher: qwenAllToolsMatcher, Hooks: []settingsHookRef{{Type: "command", Command: prefix + " post-tool", Timeout: qwenToolTimeoutMS}}},
- "PostToolUseFailure": {Matcher: qwenAllToolsMatcher, Hooks: []settingsHookRef{{Type: "command", Command: prefix + " post-tool", Timeout: qwenToolTimeoutMS}}},
- "PermissionRequest": {Matcher: qwenAllToolsMatcher, Hooks: []settingsHookRef{{Type: "command", Command: prefix + " permission-request", Timeout: qwenToolTimeoutMS}}},
- "Stop": {Hooks: []settingsHookRef{{Type: "command", Command: prefix + " stop", Timeout: qwenStopTimeoutMS}}},
- "SubagentStart": {Hooks: []settingsHookRef{{Type: "command", Command: prefix + " subagent-start"}}},
- "SubagentStop": {Hooks: []settingsHookRef{{Type: "command", Command: prefix + " subagent-stop"}}},
- "SessionEnd": {Hooks: []settingsHookRef{{Type: "command", Command: prefix + " session-end"}}},
+ "SessionStart": {Hooks: []settingsHookRef{{Type: "command", Shell: qwenHookShell, Command: prefix + " session-start"}}},
+ "UserPromptSubmit": {Hooks: []settingsHookRef{{Type: "command", Shell: qwenHookShell, Command: prefix + " prompt-submit", Timeout: qwenPromptSubmitTimeoutMS}}},
+ "PreToolUse": {Matcher: qwenAllToolsMatcher, Hooks: []settingsHookRef{{Type: "command", Shell: qwenHookShell, Command: prefix + " pre-tool", Timeout: qwenToolTimeoutMS}}},
+ "PostToolUse": {Matcher: qwenAllToolsMatcher, Hooks: []settingsHookRef{{Type: "command", Shell: qwenHookShell, Command: prefix + " post-tool", Timeout: qwenToolTimeoutMS}}},
+ "PostToolUseFailure": {Matcher: qwenAllToolsMatcher, Hooks: []settingsHookRef{{Type: "command", Shell: qwenHookShell, Command: prefix + " post-tool", Timeout: qwenToolTimeoutMS}}},
+ "PermissionRequest": {Matcher: qwenAllToolsMatcher, Hooks: []settingsHookRef{{Type: "command", Shell: qwenHookShell, Command: prefix + " permission-request", Timeout: qwenToolTimeoutMS}}},
+ "Stop": {Hooks: []settingsHookRef{{Type: "command", Shell: qwenHookShell, Command: prefix + " stop", Timeout: qwenStopTimeoutMS}}},
+ "SubagentStart": {Hooks: []settingsHookRef{{Type: "command", Shell: qwenHookShell, Command: prefix + " subagent-start"}}},
+ "SubagentStop": {Hooks: []settingsHookRef{{Type: "command", Shell: qwenHookShell, Command: prefix + " subagent-stop"}}},
+ "SessionEnd": {Hooks: []settingsHookRef{{Type: "command", Shell: qwenHookShell, Command: prefix + " session-end"}}},
}
return installSettingsEndpointHooks(path, "qwen", endpointHooks)
}
diff --git a/cli/beacon/internal/endpoint/hooks/qwen_test.go b/cli/beacon/internal/endpoint/hooks/qwen_test.go
index c75f5acf..cc450e6f 100644
--- a/cli/beacon/internal/endpoint/hooks/qwen_test.go
+++ b/cli/beacon/internal/endpoint/hooks/qwen_test.go
@@ -19,6 +19,7 @@ func decodeQwenHooks(t *testing.T, path string) map[string][]struct {
Type string `json:"type"`
Command string `json:"command"`
Timeout int `json:"timeout"`
+ Shell string `json:"shell"`
} `json:"hooks"`
} {
t.Helper()
@@ -33,6 +34,7 @@ func decodeQwenHooks(t *testing.T, path string) map[string][]struct {
Type string `json:"type"`
Command string `json:"command"`
Timeout int `json:"timeout"`
+ Shell string `json:"shell"`
} `json:"hooks"`
} `json:"hooks"`
}
@@ -392,3 +394,56 @@ func readFileString(t *testing.T, path string) string {
}
return string(data)
}
+
+// The second way this installer can look correct and collect nothing.
+//
+// Beacon builds its hook command with hookCommandQuote, which single-quotes every path on every
+// platform. That is POSIX quoting: literal in bash, and *not* valid in cmd.exe, where the quotes
+// are ordinary characters and the command never resolves to an executable. Qwen picks the shell it
+// runs a command hook with, and a Node-hosted runtime left to the Windows default lands on cmd.exe
+// -- so without this field every hook on a Windows host fails to start while `endpoint hooks
+// install` still prints success and the settings file still reads correctly.
+//
+// Same silent-failure shape as a seconds-valued timeout, and it gets the same tripwire. `bash` is
+// the only one of Qwen's two documented values that can parse what Beacon writes; `powershell`
+// would treat a quoted string in command position as an expression.
+func TestQwenHooksDeclareTheShellTheirQuotingRequires(t *testing.T) {
+ path := filepath.Join(t.TempDir(), "settings.json")
+ if err := installQwenSettings(path, `C:\Program Files\Beacon\beacon-hooks.exe`, "/tmp/runtime.jsonl", "/tmp/config.json"); err != nil {
+ t.Fatalf("installQwenSettings returned error: %v", err)
+ }
+
+ hooks := decodeQwenHooks(t, path)
+ if len(hooks) == 0 {
+ t.Fatal("no hooks installed")
+ }
+ for event, groups := range hooks {
+ for _, group := range groups {
+ for _, hook := range group.Hooks {
+ if hook.Shell != qwenHookShell {
+ t.Errorf("%s shell = %q, want %q; Beacon's command is POSIX-quoted and will not "+
+ "run under the Windows default shell", event, hook.Shell, qwenHookShell)
+ }
+ // The pairing this test is really about: the declared shell has to match the
+ // quoting actually emitted. If hookCommandQuote ever stops single-quoting, this
+ // declaration becomes a lie rather than a fix.
+ if !strings.Contains(hook.Command, `'C:\Program Files\Beacon\beacon-hooks.exe'`) {
+ t.Errorf("%s command = %q, want the binary single-quoted for %s", event, hook.Command, qwenHookShell)
+ }
+ }
+ }
+ }
+}
+
+// Declaring a shell must not leak into the runtimes that share this settings writer and do not
+// expose the field. Claude Code has no `shell` key in its hook schema, and emitting one there
+// would put an unrecognized field into a file Beacon does not own.
+func TestOnlyQwenDeclaresAHookShell(t *testing.T) {
+ path := filepath.Join(t.TempDir(), "settings.json")
+ if err := installClaudeSettings(path, "/tmp/beacon-hooks", "/tmp/runtime.jsonl", "/tmp/config.json"); err != nil {
+ t.Fatalf("installClaudeSettings returned error: %v", err)
+ }
+ if got := readFileString(t, path); strings.Contains(got, `"shell"`) {
+ t.Fatalf("Claude settings carry a shell field:\n%s", got)
+ }
+}
diff --git a/cli/beacon/internal/endpoint/hooks/settings_hooks.go b/cli/beacon/internal/endpoint/hooks/settings_hooks.go
index 1b1062bb..e1f2b5b4 100644
--- a/cli/beacon/internal/endpoint/hooks/settings_hooks.go
+++ b/cli/beacon/internal/endpoint/hooks/settings_hooks.go
@@ -12,9 +12,17 @@ type settingsHookGroup struct {
}
type settingsHookRef struct {
- Type string `json:"type,omitempty"`
- Command string `json:"command"`
- Timeout int `json:"timeout,omitempty"`
+ Type string `json:"type,omitempty"`
+ Command string `json:"command"`
+ Timeout int `json:"timeout,omitempty"`
+ // Shell names the interpreter the runtime should parse Command with, for runtimes that let a
+ // hook say. Omitted by default, so the runtimes that do not expose the field are unaffected.
+ //
+ // It exists because Command is quoted for one specific shell -- see hookCommandQuote -- and a
+ // runtime that picks a different one cannot run it at all. Saying which shell the command was
+ // written for is strictly better than emitting a second quoting dialect and hoping the runtime
+ // picks the matching one.
+ Shell string `json:"shell,omitempty"`
ShowOutput *bool `json:"show_output,omitempty"`
}