Skip to content

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

Qwen Code support 5/6: make Qwen Code installable, discoverable and visible

Justindd049942f1fb
diff --git a/cli/beacon/cmd/endpoint_diagnostics.go b/cli/beacon/cmd/endpoint_diagnostics.go
index 08c5fbcc..d370f051 100644
--- a/cli/beacon/cmd/endpoint_diagnostics.go
+++ b/cli/beacon/cmd/endpoint_diagnostics.go
@@ -869,7 +869,7 @@ func hookTargets() ([]string, error) {
}
func allHookTargetsForLevel() []string {
- all := []string{"cursor", "codex", "vscode", "factory", "opencode", "cline", "grok", "hermes", "devin-cli", "devin-desktop", "antigravity"}
+ all := []string{"cursor", "codex", "vscode", "factory", "opencode", "cline", "grok", "qwen", "hermes", "devin-cli", "devin-desktop", "antigravity"}
if endpointOpts.hookLevel != "project" {
return all
}
@@ -920,6 +920,9 @@ func hookStatusesWithConfig(targets []string, cfg endpointconfig.Config) map[str
case "cline":
status := endpointhooks.ClineHookStatus(endpointhooks.ClineOptions{Level: endpointhooks.Level(endpointOpts.hookLevel), LogPath: cfg.LogPath, UserMode: cfg.UserMode})
statuses[name] = hookTargetResult{Target: name, Status: targetStatus(status.Installed), Installed: status.Installed, Message: status.Message, Path: status.PluginPath, Raw: status}
+ case "qwen":
+ status := endpointhooks.QwenHookStatus(endpointhooks.QwenOptions{Level: endpointhooks.Level(endpointOpts.hookLevel), LogPath: cfg.LogPath, UserMode: cfg.UserMode})
+ statuses[name] = hookTargetResult{Target: name, Status: targetStatus(status.Installed), Installed: status.Installed, Message: status.Message, Path: status.SettingsPath, Raw: status}
case "grok":
status := endpointhooks.GrokHookStatus(endpointhooks.GrokOptions{Level: endpointhooks.Level(endpointOpts.hookLevel), LogPath: cfg.LogPath, UserMode: cfg.UserMode})
statuses[name] = hookTargetResult{Target: name, Status: targetStatus(status.Installed), Installed: status.Installed, Message: status.Message, Path: status.HooksPath, Raw: status}
diff --git a/cli/beacon/cmd/endpoint_hooks.go b/cli/beacon/cmd/endpoint_hooks.go
index 61b7f08c..0921d7ab 100644
--- a/cli/beacon/cmd/endpoint_hooks.go
+++ b/cli/beacon/cmd/endpoint_hooks.go
@@ -153,6 +153,22 @@ func installEndpointHookTarget(name string, cfg endpointconfig.Config) error {
if strings.Contains(status.Message, "/hooks-trust") {
fmt.Println(status.Message)
}
+ case "qwen":
+ status, err := endpointhooks.InstallQwen(endpointhooks.QwenOptions{
+ Level: endpointhooks.Level(endpointOpts.hookLevel),
+ LogPath: cfg.LogPath,
+ UserMode: cfg.UserMode,
+ })
+ if err != nil {
+ return err
+ }
+ fmt.Printf("Qwen Code hooks installed: %s\n", status.SettingsPath)
+ // Printed only when it applies. A project-level install into an untrusted folder writes a
+ // file that does nothing until the user trusts the folder, and silence there would read as
+ // "collecting".
+ if strings.Contains(status.Message, "trusted") {
+ fmt.Println(status.Message)
+ }
case "hermes":
status, err := endpointhooks.InstallHermes(endpointhooks.HermesOptions{
Level: endpointhooks.Level(endpointOpts.hookLevel),
@@ -305,6 +321,16 @@ func uninstallEndpointHookTarget(name string, cfg endpointconfig.Config) error {
return err
}
fmt.Println(status.Message)
+ case "qwen":
+ status, err := endpointhooks.UninstallQwen(endpointhooks.QwenOptions{
+ Level: endpointhooks.Level(endpointOpts.hookLevel),
+ LogPath: cfg.LogPath,
+ UserMode: cfg.UserMode,
+ })
+ if err != nil {
+ return err
+ }
+ fmt.Println(status.Message)
case "hermes":
status, err := endpointhooks.UninstallHermes(endpointhooks.HermesOptions{
Level: endpointhooks.Level(endpointOpts.hookLevel),
@@ -405,6 +431,12 @@ func runEndpointHooksStatus(cmd *cobra.Command, args []string) error {
LogPath: cfg.LogPath,
UserMode: cfg.UserMode,
})
+ case "qwen":
+ statuses["qwen"] = endpointhooks.QwenHookStatus(endpointhooks.QwenOptions{
+ Level: endpointhooks.Level(endpointOpts.hookLevel),
+ LogPath: cfg.LogPath,
+ UserMode: cfg.UserMode,
+ })
case "hermes":
statuses["hermes"] = endpointhooks.HermesHookStatus(endpointhooks.HermesOptions{
Level: endpointhooks.Level(endpointOpts.hookLevel),
@@ -465,6 +497,10 @@ func runEndpointHooksStatus(cmd *cobra.Command, args []string) error {
status := statuses["grok"].(endpointhooks.GrokStatus)
fmt.Printf("Grok hooks: installed=%t path=%s\n", status.Installed, status.HooksPath)
fmt.Println(status.Message)
+ case "qwen":
+ status := statuses["qwen"].(endpointhooks.QwenStatus)
+ fmt.Printf("Qwen Code hooks: installed=%t path=%s\n", status.Installed, status.SettingsPath)
+ fmt.Println(status.Message)
case "hermes":
status := statuses["hermes"].(endpointhooks.HermesStatus)
fmt.Printf("Hermes Agent hooks: installed=%t path=%s\n", status.Installed, status.ConfigPath)
diff --git a/cli/beacon/cmd/endpoint_hooks_repair.go b/cli/beacon/cmd/endpoint_hooks_repair.go
index 66c4b241..9b5dbdb4 100644
--- a/cli/beacon/cmd/endpoint_hooks_repair.go
+++ b/cli/beacon/cmd/endpoint_hooks_repair.go
@@ -148,7 +148,7 @@ func installedHookTargetsForUser(homeDir, logPath string) ([]string, error) {
}
func repairTargetOrder() []string {
- return []string{"claude", "codex", "cursor", "vscode", "factory", "opencode", "cline", "grok", "hermes", "devin-cli", "devin-desktop", "antigravity"}
+ return []string{"claude", "codex", "cursor", "vscode", "factory", "opencode", "cline", "grok", "qwen", "hermes", "devin-cli", "devin-desktop", "antigravity"}
}
// withUserHome runs fn as if it were executing inside another user's profile.
diff --git a/cli/beacon/cmd/endpoint_hooks_test.go b/cli/beacon/cmd/endpoint_hooks_test.go
index d8ad59d1..d3394105 100644
--- a/cli/beacon/cmd/endpoint_hooks_test.go
+++ b/cli/beacon/cmd/endpoint_hooks_test.go
@@ -1,6 +1,7 @@
package cmd
import (
+ "os"
"path/filepath"
"strings"
"testing"
@@ -41,3 +42,56 @@ func TestEveryHookTargetIsWired(t *testing.T) {
t.Error("cline is missing from the hook target registry")
}
}
+
+// The install -> status -> uninstall round trip for Qwen Code, through the CLI entry points rather
+// than the package API.
+//
+// Wiring a runtime into `beacon endpoint hooks` means five separate switches (install, uninstall,
+// status collection, status printing, repair) plus a registry row, and every one of them fails by
+// omission rather than by error. TestEveryHookTargetIsWired proves each switch has a case; this
+// proves the cases do the thing their name claims.
+func TestEndpointHooksInstallAndUninstallQwen(t *testing.T) {
+ home := t.TempDir()
+ t.Setenv("HOME", home)
+ t.Setenv("USERPROFILE", home)
+ cfg := endpointconfig.Config{LogPath: filepath.Join(home, "runtime.jsonl"), UserMode: true}
+
+ origLevel := endpointOpts.hookLevel
+ t.Cleanup(func() { endpointOpts.hookLevel = origLevel })
+ endpointOpts.hookLevel = "user"
+
+ settings := filepath.Join(home, ".qwen", "settings.json")
+ if err := installEndpointHookTarget("qwen", cfg); err != nil {
+ t.Fatalf("installEndpointHookTarget(qwen) returned error: %v", err)
+ }
+ data, err := os.ReadFile(settings)
+ if err != nil {
+ t.Fatalf("install did not write %s: %v", settings, err)
+ }
+ if !strings.Contains(string(data), "--platform qwen") {
+ t.Fatalf("settings do not carry the Qwen hook command:\n%s", data)
+ }
+
+ if err := uninstallEndpointHookTarget("qwen", cfg); err != nil {
+ t.Fatalf("uninstallEndpointHookTarget(qwen) returned error: %v", err)
+ }
+ data, err = os.ReadFile(settings)
+ if err != nil {
+ t.Fatalf("uninstall removed the settings file itself: %v", err)
+ }
+ if strings.Contains(string(data), "--platform qwen") {
+ t.Fatalf("uninstall left the Qwen hook behind:\n%s", data)
+ }
+}
+
+// `endpoint hooks repair` walks a hard-coded list rather than the registry, so a runtime absent
+// from it is never repaired -- and repair is what fixes a hook whose binary path went stale after
+// an upgrade. It fails silently: repair reports success having skipped the runtime entirely.
+func TestQwenIsInTheRepairTargetList(t *testing.T) {
+ for _, name := range repairTargetOrder() {
+ if name == "qwen" {
+ return
+ }
+ }
+ t.Fatal("qwen is missing from the repair target list; `endpoint repair` would silently skip it")
+}
diff --git a/cli/beacon/cmd/endpoint_targets.go b/cli/beacon/cmd/endpoint_targets.go
index 6c39e434..17df8765 100644
--- a/cli/beacon/cmd/endpoint_targets.go
+++ b/cli/beacon/cmd/endpoint_targets.go
@@ -47,6 +47,10 @@ var harnessTargets = []harnessTarget{
{name: "opencode", endpointKind: endpointTargetHook, endpointAliases: []string{"opencode"}, hookAliases: []string{"opencode"}},
{name: "cline", endpointKind: endpointTargetHook, endpointAliases: []string{"cline"}, hookAliases: []string{"cline"}},
{name: "grok", endpointKind: endpointTargetHook, endpointAliases: []string{"grok"}, hookAliases: []string{"grok"}},
+ // "qwen-code" and "qwen_code" both normalize to "qwen-code" through normalizeHarnessKey, so the
+ // two spellings need one alias between them. "qwen-cli" is not accepted: the product is Qwen
+ // Code, and an alias nobody uses is an alias to keep working.
+ {name: "qwen", endpointKind: endpointTargetHook, endpointAliases: []string{"qwen", "qwen-code"}, hookAliases: []string{"qwen", "qwen-code"}},
{name: "hermes", endpointKind: endpointTargetHook, endpointAliases: []string{"hermes", "hermes-agent"}, hookAliases: []string{"hermes", "hermes-agent"}},
{name: "antigravity", endpointKind: endpointTargetHook, endpointAliases: []string{"antigravity", "antigravity-cli"}, hookAliases: []string{"antigravity", "antigravity-cli"}},
{name: "devin-cli", endpointKind: endpointTargetHook, endpointAliases: []string{"devin", "devin-cli"}, hookAliases: []string{"devin", "devin-cli"}},
diff --git a/cli/beacon/cmd/endpoint_targets_characterization_test.go b/cli/beacon/cmd/endpoint_targets_characterization_test.go
index 1a320102..8a8fe1d0 100644
--- a/cli/beacon/cmd/endpoint_targets_characterization_test.go
+++ b/cli/beacon/cmd/endpoint_targets_characterization_test.go
@@ -34,6 +34,9 @@ func TestNormalizeEndpointTargetCharacterization(t *testing.T) {
"opencode": {"opencode", endpointTargetHook, true},
"cline": {"cline", endpointTargetHook, true},
"grok": {"grok", endpointTargetHook, true},
+ "qwen": {"qwen", endpointTargetHook, true},
+ "qwen-code": {"qwen", endpointTargetHook, true},
+ "qwen_code": {"qwen", endpointTargetHook, true},
"hermes": {"hermes", endpointTargetHook, true},
"hermes-agent": {"hermes", endpointTargetHook, true},
"antigravity": {"antigravity", endpointTargetHook, true},
@@ -85,6 +88,9 @@ func TestNormalizeHookTargetCharacterization(t *testing.T) {
"opencode": {"opencode", true},
"cline": {"cline", true},
"grok": {"grok", true},
+ "qwen": {"qwen", true},
+ "qwen-code": {"qwen", true},
+ "qwen_code": {"qwen", true},
"hermes": {"hermes", true},
"hermes-agent": {"hermes", true},
"devin": {"devin-cli", true},
diff --git a/cli/beacon/internal/endpoint/dashboard/hooks_status_test.go b/cli/beacon/internal/endpoint/dashboard/hooks_status_test.go
index 8fdf5bfc..94a06e0b 100644
--- a/cli/beacon/internal/endpoint/dashboard/hooks_status_test.go
+++ b/cli/beacon/internal/endpoint/dashboard/hooks_status_test.go
@@ -53,3 +53,33 @@ func TestHookStatusesReportClineWithItsPluginPath(t *testing.T) {
}
t.Fatal("no cline row in the hook status list")
}
+
+// The dashboard's runtime list is separate from the CLI's target registry, so a runtime wired into
+// `beacon endpoint hooks` but not here is invisible in the inventory view with no error to say the
+// view is incomplete. A row also has to carry a path: "not_installed" with no path tells an
+// operator nothing about where to look.
+func TestHookStatusesReportQwenWithItsSettingsPath(t *testing.T) {
+ home := t.TempDir()
+ t.Setenv("HOME", home)
+ t.Setenv("USERPROFILE", home)
+
+ rows := 0
+ for _, status := range hookStatuses(filepath.Join(t.TempDir(), "runtime.jsonl"), true) {
+ if status.Target != "qwen" {
+ continue
+ }
+ rows++
+ if status.Installed {
+ t.Errorf("qwen reported installed with no settings file present: %+v", status)
+ }
+ if status.Status != "not_installed" {
+ t.Errorf("qwen status = %q, want not_installed", status.Status)
+ }
+ if want := filepath.Join(home, ".qwen", "settings.json"); status.Path != want {
+ t.Errorf("qwen path = %q, want %q", status.Path, want)
+ }
+ }
+ if rows != 1 {
+ t.Fatalf("qwen appears %d times in the hook status list, want exactly 1", rows)
+ }
+}
diff --git a/cli/beacon/internal/endpoint/dashboard/server.go b/cli/beacon/internal/endpoint/dashboard/server.go
index b2c5fb01..ed7eb27a 100644
--- a/cli/beacon/internal/endpoint/dashboard/server.go
+++ b/cli/beacon/internal/endpoint/dashboard/server.go
@@ -345,6 +345,8 @@ func hookStatuses(logPath string, userMode bool) []HookStatus {
add("hermes", hermes.Installed, hermes.ConfigPath, hermes.BinaryPath, hermes.Message)
opencode := endpointhooks.OpenCodeHookStatus(endpointhooks.OpenCodeOptions{Level: level, LogPath: logPath, UserMode: userMode})
add("opencode", opencode.Installed, opencode.PluginPath, opencode.BinaryPath, opencode.Message)
+ qwen := endpointhooks.QwenHookStatus(endpointhooks.QwenOptions{Level: level, LogPath: logPath, UserMode: userMode})
+ add("qwen", qwen.Installed, qwen.SettingsPath, qwen.BinaryPath, qwen.Message)
vscode := endpointhooks.VSCodeHookStatus(endpointhooks.VSCodeOptions{Level: level, LogPath: logPath, UserMode: userMode})
add("vscode", vscode.Installed, vscode.HooksPath, vscode.BinaryPath, vscode.Message)
return out
diff --git a/cli/beacon/internal/endpoint/dashboard/static/app.js b/cli/beacon/internal/endpoint/dashboard/static/app.js
index 1cbdcd1f..5bde5382 100644
--- a/cli/beacon/internal/endpoint/dashboard/static/app.js
+++ b/cli/beacon/internal/endpoint/dashboard/static/app.js
@@ -631,6 +631,8 @@ function runtimeLabel(value) {
"devin-cli": "Devin CLI",
"devin-desktop": "Devin Desktop",
grok: "Grok",
+ qwen: "Qwen Code",
+ qwen_code: "Qwen Code",
agent_skills: "Agent Skills",
};
return labels[value] || harnessLabel(value);
@@ -969,6 +971,7 @@ function harnessLabel(value) {
codex_cli: "Codex CLI",
copilot_cli: "GitHub Copilot CLI",
grok: "Grok Build",
+ qwen_code: "Qwen Code",
cli: "Beacon CLI",
};
return labels[value] || value;
diff --git a/cli/beacon/internal/endpoint/harness/harness.go b/cli/beacon/internal/endpoint/harness/harness.go
index efe1a4ba..b890fd6e 100644
--- a/cli/beacon/internal/endpoint/harness/harness.go
+++ b/cli/beacon/internal/endpoint/harness/harness.go
@@ -58,6 +58,7 @@ func DiscoverAll() []Harness {
DiscoverOpenCode(),
DiscoverCline(),
DiscoverPi(),
+ DiscoverQwen(),
DiscoverHermes(),
DiscoverFactory(),
DiscoverVSCode(),
diff --git a/cli/beacon/internal/endpoint/harness/qwen.go b/cli/beacon/internal/endpoint/harness/qwen.go
new file mode 100644
index 00000000..a43c6135
--- /dev/null
+++ b/cli/beacon/internal/endpoint/harness/qwen.go
@@ -0,0 +1,78 @@
+package harness
+
+import (
+ "encoding/json"
+ "os"
+ "path/filepath"
+ "strings"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/hooks"
+)
+
+// DiscoverQwen reports whether Qwen Code is present and whether Beacon's hooks are installed for it.
+//
+// Its capability is "hooks" rather than "otel_env" or "otel_config": Qwen Code is a Gemini CLI fork
+// but does not carry Gemini's OpenTelemetry export, so there is no endpoint to point at the local
+// collector. What it does expose is a documented hook system, and what this function reports is the
+// state of Beacon's entries inside Qwen's own settings.json.
+func DiscoverQwen() Harness {
+ h := Harness{Name: "qwen_code", DisplayName: "Qwen Code", Capability: "hooks"}
+ detectExecutable(&h, "qwen")
+
+ home, _ := os.UserHomeDir()
+
+ // A missing home directory leaves the config path empty rather than resolving to the relative
+ // ".qwen/settings.json", which is exactly where a *project* install lives. Discovery would
+ // otherwise read whatever repository the command ran from and report it as the machine's state.
+ // DiscoverCline and DiscoverPi guard the same way.
+ settingsPath, err := hooks.QwenSettingsPath(hooks.LevelUser)
+ if err != nil {
+ h.TelemetryStatus = TelemetryMissing
+ h.Message = "Qwen Code settings directory could not be resolved: " + err.Error()
+ return h
+ }
+ h.ConfigPath = settingsPath
+
+ // Qwen Code installs through npm, and a version manager, a shell alias or a per-project install
+ // all hide the binary from the PATH this process inherited while ~/.qwen is still there.
+ // Treating that directory as evidence keeps `endpoint discover` from reporting "not detected"
+ // for a runtime the user is actively using -- the same fallback the opencode, Cursor, Pi and
+ // Hermes probes make for the same reason.
+ if !h.Detected && dirExists(filepath.Join(home, ".qwen")) {
+ h.Detected = true
+ }
+
+ h.TelemetryStatus, h.Message = qwenStatus(settingsPath)
+ return h
+}
+
+// qwenStatus classifies Qwen Code's settings file.
+//
+// Four outcomes, and the middle two are the ones worth spelling out. A settings file with hooks
+// that are not Beacon's is *disabled*, not enabled: reporting it as enabled would claim telemetry
+// Beacon is not collecting. Invalid JSON is *misconfigured* rather than missing, because install
+// will refuse to touch that file and the user needs to know why -- reporting "not found" for a file
+// that is right there sends them looking in the wrong place.
+func qwenStatus(path string) (TelemetryStatus, string) {
+ data, err := os.ReadFile(path)
+ if err != nil {
+ if os.IsNotExist(err) {
+ return TelemetryMissing, "Qwen Code settings file was not found"
+ }
+ return TelemetryMissing, err.Error()
+ }
+ var settings map[string]interface{}
+ if err := json.Unmarshal(data, &settings); err != nil {
+ return TelemetryMisconfigured, "Qwen Code settings JSON is invalid"
+ }
+ // Qwen's own kill switch. Beacon's hooks can be present in the file and still never run, and
+ // "installed but disabled" is a different problem from "not installed" -- it is fixed in Qwen's
+ // settings, not by re-running the installer.
+ if disabled, ok := settings["disableAllHooks"].(bool); ok && disabled {
+ return TelemetryDisabled, "Qwen Code hooks are disabled by disableAllHooks in settings.json"
+ }
+ if !strings.Contains(string(data), "--platform qwen") && !strings.Contains(string(data), "--platform=qwen") {
+ return TelemetryDisabled, "Qwen Code settings file exists but Beacon endpoint hooks were not found"
+ }
+ return TelemetryEnabled, "Beacon Qwen Code hooks are configured"
+}
diff --git a/cli/beacon/internal/endpoint/harness/qwen_test.go b/cli/beacon/internal/endpoint/harness/qwen_test.go
new file mode 100644
index 00000000..552b91b5
--- /dev/null
+++ b/cli/beacon/internal/endpoint/harness/qwen_test.go
@@ -0,0 +1,131 @@
+package harness
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
+)
+
+// A runtime missing from DiscoverAll is invisible to `beacon endpoint discover`, which is where an
+// operator looks to find out what is on the machine. It fails silently: the command succeeds and
+// simply never mentions Qwen Code.
+func TestDiscoverAllIncludesQwen(t *testing.T) {
+ for _, h := range DiscoverAll() {
+ if h.Name == "qwen_code" {
+ if h.DisplayName != "Qwen Code" {
+ t.Errorf("DisplayName = %q, want Qwen Code", h.DisplayName)
+ }
+ // "hooks", not "otel_env": Qwen Code is a Gemini CLI fork without Gemini's
+ // OpenTelemetry export, so there is no endpoint to point at the local collector and
+ // `endpoint install --harness qwen` has nothing to configure.
+ if h.Capability != "hooks" {
+ t.Errorf("Capability = %q, want hooks", h.Capability)
+ }
+ return
+ }
+ }
+ t.Fatal("DiscoverAll does not include qwen_code; `beacon endpoint discover` would never mention it")
+}
+
+// Qwen Code installs through npm, so a version manager, a shell alias or a per-project install all
+// hide the binary from the PATH this process inherited while ~/.qwen is still there. Reporting "not
+// detected" for a runtime the user is actively using is the failure this guards.
+func TestDiscoverQwenDetectsConfigDirectoryWithoutAnExecutable(t *testing.T) {
+ home := t.TempDir()
+ testenv.SetHome(t, home)
+ t.Setenv("PATH", t.TempDir())
+ if err := os.MkdirAll(filepath.Join(home, ".qwen"), 0755); err != nil {
+ t.Fatalf("mkdir qwen config dir: %v", err)
+ }
+
+ h := DiscoverQwen()
+ if !h.Detected {
+ t.Fatalf("DiscoverQwen did not detect Qwen Code from its config directory: %#v", h)
+ }
+ if h.ExecutablePath != "" {
+ t.Fatalf("ExecutablePath = %q, want empty with no binary on PATH", h.ExecutablePath)
+ }
+ if want := filepath.Join(home, ".qwen", "settings.json"); h.ConfigPath != want {
+ t.Fatalf("ConfigPath = %q, want %q", h.ConfigPath, want)
+ }
+ if h.TelemetryStatus != TelemetryMissing {
+ t.Fatalf("TelemetryStatus = %q, want %q with no settings file", h.TelemetryStatus, TelemetryMissing)
+ }
+}
+
+func TestDiscoverQwenTelemetryStatusVariants(t *testing.T) {
+ beaconHook := `{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"'/tmp/beacon-hooks' --platform qwen stop"}]}]}}`
+ cases := []struct {
+ name string
+ settings string
+ want TelemetryStatus
+ message string
+ }{
+ {name: "beacon hooks installed", settings: beaconHook, want: TelemetryEnabled, message: "configured"},
+ // Someone else's hooks in the same file. Reporting that as enabled would claim telemetry
+ // Beacon is not collecting.
+ {name: "only the user's own hooks", settings: `{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"my-own.sh"}]}]}}`, want: TelemetryDisabled, message: "were not found"},
+ // Qwen's own kill switch. Beacon's hooks are in the file and will never run, which is a
+ // different problem from "not installed" and is fixed in Qwen's settings rather than by
+ // re-running the installer.
+ {name: "disableAllHooks", settings: `{"disableAllHooks":true,` + beaconHook[1:], want: TelemetryDisabled, message: "disableAllHooks"},
+ // Misconfigured, not missing: install refuses to touch an unparseable file, and reporting
+ // "not found" for a file that is right there sends the user looking in the wrong place.
+ {name: "invalid JSON", settings: `{not json`, want: TelemetryMisconfigured, message: "invalid"},
+ }
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ home := t.TempDir()
+ testenv.SetHome(t, home)
+ t.Setenv("PATH", t.TempDir())
+ path := filepath.Join(home, ".qwen", "settings.json")
+ if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
+ t.Fatalf("mkdir qwen config dir: %v", err)
+ }
+ if err := os.WriteFile(path, []byte(tc.settings), 0600); err != nil {
+ t.Fatalf("write qwen settings: %v", err)
+ }
+
+ h := DiscoverQwen()
+ if h.TelemetryStatus != tc.want {
+ t.Fatalf("TelemetryStatus = %q, want %q (message %q)", h.TelemetryStatus, tc.want, h.Message)
+ }
+ if !strings.Contains(h.Message, tc.message) {
+ t.Fatalf("Message = %q, want it to mention %q", h.Message, tc.message)
+ }
+ })
+ }
+}
+
+// The user path and the project path differ only by the home prefix -- `~/.qwen/settings.json`
+// against `.qwen/settings.json`. So an unresolvable home directory does not merely produce a
+// useless path: it produces exactly the path a project install occupies, and discovery would read
+// a repository's own settings and report them as the machine's state. DiscoverCline and DiscoverPi
+// guard the same way.
+func TestDiscoverQwenDoesNotFallBackToTheProjectPath(t *testing.T) {
+ testenv.SetHome(t, "")
+ t.Setenv("PATH", t.TempDir())
+
+ // A project-shaped settings file in the working directory, which is what a relative path would
+ // pick up.
+ work := t.TempDir()
+ t.Chdir(work)
+ path := filepath.Join(work, ".qwen", "settings.json")
+ if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
+ t.Fatalf("mkdir project qwen dir: %v", err)
+ }
+ if err := os.WriteFile(path, []byte(`{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"beacon-hooks --platform qwen stop"}]}]}}`), 0600); err != nil {
+ t.Fatalf("write project settings: %v", err)
+ }
+
+ h := DiscoverQwen()
+ if h.ConfigPath == filepath.Join(".qwen", "settings.json") {
+ t.Fatalf("ConfigPath = %q; a relative path reads the current repository as the machine's state", h.ConfigPath)
+ }
+ if h.TelemetryStatus == TelemetryEnabled {
+ t.Fatalf("TelemetryStatus = enabled from a project settings file: %#v", h)
+ }
+}
diff --git a/cli/beacon/internal/endpoint/hooks/qwen.go b/cli/beacon/internal/endpoint/hooks/qwen.go
index ff02d541..b2366da3 100644
--- a/cli/beacon/internal/endpoint/hooks/qwen.go
+++ b/cli/beacon/internal/endpoint/hooks/qwen.go
@@ -50,7 +50,7 @@ type QwenStatus struct {
var qwenRuntime = hookRuntime{
displayName: "Qwen Code",
- configPath: qwenSettingsPath,
+ configPath: QwenSettingsPath,
install: installQwenSettings,
uninstall: removeQwenEndpointHooks,
isInstalled: isQwenInstalledAt,
@@ -132,13 +132,19 @@ func isQwenInstalledAt(path string) bool {
return isSettingsEndpointInstalledAt(path, "qwen")
}
-// qwenSettingsPath returns the settings file Beacon merges into for a given install level.
+// QwenSettingsPath returns the settings file Beacon merges into for a given install level.
//
// Qwen Code resolves settings from `~/.qwen/settings.json` for the user and `.qwen/settings.json`
// in the project root, with project settings taking precedence. The user level is the default here
// for the same reason it is elsewhere: a project-level install only takes effect once the folder is
// trusted, so it is the one that needs a caveat rather than the one to reach for first.
-func qwenSettingsPath(level Level) (string, error) {
+//
+// Exported because `harness` reports on the same file and must not rebuild the path itself. Two
+// copies of "where the settings live" is how discovery comes to report on a file the installer does
+// not write -- and here it would do so in the worst way: an unresolved home directory turns the
+// user path into the *project* path, so discovery would read whatever repository the command ran
+// from and report it as the machine's state.
+func QwenSettingsPath(level Level) (string, error) {
switch level {
case "", LevelUser:
home, err := os.UserHomeDir()
diff --git a/cli/beacon/internal/endpoint/hooks/qwen_test.go b/cli/beacon/internal/endpoint/hooks/qwen_test.go
index c75f5acf..e6c4ca65 100644
--- a/cli/beacon/internal/endpoint/hooks/qwen_test.go
+++ b/cli/beacon/internal/endpoint/hooks/qwen_test.go
@@ -280,30 +280,30 @@ func TestQwenSettingsPathUserAndProjectLevels(t *testing.T) {
home := t.TempDir()
testenv.SetHome(t, home)
- userPath, err := qwenSettingsPath(LevelUser)
+ userPath, err := QwenSettingsPath(LevelUser)
if err != nil {
- t.Fatalf("qwenSettingsPath(user) returned error: %v", err)
+ t.Fatalf("QwenSettingsPath(user) returned error: %v", err)
}
if want := filepath.Join(home, ".qwen", "settings.json"); userPath != want {
t.Errorf("user settings path = %q, want %q", userPath, want)
}
// An empty level means the user level, which is what an unset --level flag produces.
- if defaulted, err := qwenSettingsPath(""); err != nil || defaulted != userPath {
- t.Errorf("qwenSettingsPath(\"\") = %q, %v; want the user path", defaulted, err)
+ if defaulted, err := QwenSettingsPath(""); err != nil || defaulted != userPath {
+ t.Errorf("QwenSettingsPath(\"\") = %q, %v; want the user path", defaulted, err)
}
project := t.TempDir()
t.Chdir(project)
- projectPath, err := qwenSettingsPath(LevelProject)
+ projectPath, err := QwenSettingsPath(LevelProject)
if err != nil {
- t.Fatalf("qwenSettingsPath(project) returned error: %v", err)
+ t.Fatalf("QwenSettingsPath(project) returned error: %v", err)
}
if want := filepath.Join(project, ".qwen", "settings.json"); projectPath != want {
t.Errorf("project settings path = %q, want %q", projectPath, want)
}
- if _, err := qwenSettingsPath(Level("nonsense")); err == nil {
- t.Error("qwenSettingsPath(nonsense) returned no error")
+ if _, err := QwenSettingsPath(Level("nonsense")); err == nil {
+ t.Error("QwenSettingsPath(nonsense) returned no error")
}
}
diff --git a/cli/beacon/internal/endpoint/inventory/inventory.go b/cli/beacon/internal/endpoint/inventory/inventory.go
index de6da3b2..4a15f93f 100644
--- a/cli/beacon/internal/endpoint/inventory/inventory.go
+++ b/cli/beacon/internal/endpoint/inventory/inventory.go
@@ -205,6 +205,7 @@ func candidates(home, wd string) []candidate {
items = append(items, hermesCandidates(home)...)
items = append(items, devinCandidates(home, wd)...)
items = append(items, grokCandidates(home, wd)...)
+ items = append(items, qwenCandidates(home, wd)...)
seen := map[string]bool{}
out := make([]candidate, 0, len(items))
for _, item := range items {
@@ -304,6 +305,17 @@ func devinCandidates(home, wd string) []candidate {
}
}
+// Qwen Code keeps hooks in the same settings.json as the rest of its configuration, so this is a
+// native config file that Beacon merges into rather than a file Beacon owns. That is why it is
+// classified KindHookConfig and detected by the hook command it contains rather than by a
+// Beacon-managed marker: there is no marker to write into a file the user also edits.
+func qwenCandidates(home, wd string) []candidate {
+ return []candidate{
+ {runtime: "qwen_code", path: filepath.Join(home, ".qwen", "settings.json"), scope: ScopeUser, format: formatJSON, kind: KindHookConfig},
+ {runtime: "qwen_code", path: filepath.Join(wd, ".qwen", "settings.json"), scope: ScopeProject, format: formatJSON, kind: KindHookConfig},
+ }
+}
+
func grokCandidates(home, wd string) []candidate {
return []candidate{
{runtime: "grok", path: filepath.Join(home, ".grok", "hooks", "beacon-endpoint.json"), scope: ScopeUser, format: formatJSON, kind: KindHookConfig},
@@ -624,6 +636,11 @@ func beaconManaged(item candidate, data []byte) bool {
return strings.Contains(text, "beacon-managed-cline-plugin:v1")
case "grok":
return strings.Contains(text, "beacon-managed-grok-hooks:v1")
+ // Matched on the hook command rather than on a marker, because Beacon merges into Qwen's own
+ // settings.json and has no file of its own there to stamp. `--platform qwen` is what the
+ // installer writes and what uninstall keys on, so it is the same string in all three places.
+ case "qwen_code":
+ return strings.Contains(text, "--platform qwen") || strings.Contains(text, "--platform=qwen")
}
if item.runtime == "claude_code" || item.runtime == "codex_cli" {
if strings.Contains(text, "OTEL_EXPORTER_OTLP_ENDPOINT") && localEndpointText(text) {
diff --git a/cli/beacon/internal/endpoint/inventory/inventory_test.go b/cli/beacon/internal/endpoint/inventory/inventory_test.go
index fd4060a3..a71ad437 100644
--- a/cli/beacon/internal/endpoint/inventory/inventory_test.go
+++ b/cli/beacon/internal/endpoint/inventory/inventory_test.go
@@ -347,6 +347,8 @@ func TestScanIncludesAllSupportedCurrentUserAndProjectConfigs(t *testing.T) {
{runtime: "devin-desktop", path: filepath.Join(work, ".windsurf", "hooks.json"), scope: ScopeProject, format: formatJSON, kind: KindHookConfig},
{runtime: "grok", path: filepath.Join(home, ".grok", "hooks", "beacon-endpoint.json"), scope: ScopeUser, format: formatJSON, kind: KindHookConfig},
{runtime: "grok", path: filepath.Join(work, ".grok", "hooks", "beacon-endpoint.json"), scope: ScopeProject, format: formatJSON, kind: KindHookConfig},
+ {runtime: "qwen_code", path: filepath.Join(home, ".qwen", "settings.json"), scope: ScopeUser, format: formatJSON, kind: KindHookConfig},
+ {runtime: "qwen_code", path: filepath.Join(work, ".qwen", "settings.json"), scope: ScopeProject, format: formatJSON, kind: KindHookConfig},
}
if got, want := len(result.Configs), len(expected); got != want {
t.Fatalf("config candidates = %d, want %d", got, want)
@@ -890,3 +892,27 @@ func findSkill(skills []Skill, runtime, name, manifestPath string) *Skill {
}
return nil
}
+
+// Qwen Code's hooks live in the same settings.json as the rest of its configuration, so Beacon has
+// no file of its own there to stamp with a marker. Detection keys on the hook command instead, and
+// both directions matter: missing the install reports telemetry as absent on a machine that has it,
+// and claiming another runtime's hooks attributes someone else's install to Qwen.
+func TestQwenManagedDetectionReadsTheHookCommand(t *testing.T) {
+ for name, tc := range map[string]struct {
+ settings string
+ want bool
+ }{
+ "flag form": {`{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"'/opt/beacon/hooks/beacon-hooks' --platform qwen --log '/tmp/runtime.jsonl' stop"}]}]}}`, true},
+ "equals form": {`{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"beacon-hooks --platform=qwen stop"}]}]}}`, true},
+ "another runtime": {`{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"beacon-hooks --platform claude stop"}]}]}}`, false},
+ "the user's own": {`{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"my-own.sh"}]}]}}`, false},
+ "no hooks at all": {`{"theme":"Dracula"}`, false},
+ } {
+ t.Run(name, func(t *testing.T) {
+ got := beaconManaged(candidate{runtime: "qwen_code"}, []byte(tc.settings))
+ if got != tc.want {
+ t.Errorf("beaconManaged(qwen_code) = %t, want %t for %s", got, tc.want, tc.settings)
+ }
+ })
+ }
+}
diff --git a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go b/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
index 31066d9c..b326ca47 100644
--- a/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
+++ b/cli/beacon/internal/endpoint/lifecycle/lifecycle.go
@@ -810,6 +810,12 @@ func configureHarnesses(cfg endpointconfig.Config) ([]string, error) {
return paths, fmt.Errorf("opencode telemetry is installed with `beacon endpoint hooks install --harness opencode`, not endpoint install")
case "cline":
return paths, fmt.Errorf("Cline telemetry is installed with `beacon endpoint hooks install --harness cline`, not endpoint install")
+ // Qwen Code has no OpenTelemetry export to point at the local collector, so `endpoint
+ // install --harness qwen` has nothing to configure. Saying so beats the generic
+ // "unsupported harness", which reads as "Beacon does not support Qwen Code" when the
+ // support exists behind a different command.
+ case "qwen", "qwen_code":
+ return paths, fmt.Errorf("Qwen Code telemetry is installed with `beacon endpoint hooks install --harness qwen`, not endpoint install")
case "copilot", "copilot_cli", "github_copilot":
return paths, fmt.Errorf("Copilot CLI telemetry is MDM-managed; set COPILOT_OTEL_ENABLED=true and OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:%d in the Copilot CLI launch environment instead of using --harness %s", cfg.Collector.HTTPPort, name)
case "factory", "droid":
diff --git a/cli/beacon/internal/endpoint/lifecycle/lifecycle_test.go b/cli/beacon/internal/endpoint/lifecycle/lifecycle_test.go
index f69ee3e5..a5f58cc1 100644
--- a/cli/beacon/internal/endpoint/lifecycle/lifecycle_test.go
+++ b/cli/beacon/internal/endpoint/lifecycle/lifecycle_test.go
@@ -920,3 +920,17 @@ func TestGetStatusAndResolveRuntimeLogReportRequestedConfig(t *testing.T) {
t.Fatal("GetStatus should populate Version")
}
}
+
+// Qwen Code is a Gemini CLI fork without Gemini's OpenTelemetry export, so `endpoint install
+// --harness qwen` has nothing to point at the local collector. Naming the command that does work
+// matters more here than for most runtimes: the generic "unsupported harness" would read as "Beacon
+// does not support Qwen Code" when the support exists one command over.
+func TestConfigureHarnessesRejectsQwenAsHookManaged(t *testing.T) {
+ for _, name := range []string{"qwen", "qwen_code"} {
+ cfg := endpointconfig.Config{Harnesses: []string{name}}
+ _, err := configureHarnesses(cfg)
+ if err == nil || !strings.Contains(err.Error(), "endpoint hooks install --harness qwen") {
+ t.Fatalf("configureHarnesses(%q) error = %v, want the Qwen hook-managed error", name, err)
+ }
+ }
+}