diff --git a/docs/installation.md b/docs/installation.md index 38ea09f5a..acc285e69 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -135,10 +135,17 @@ listed after the table because its connector is not one of these files: | Antigravity | `antigravity` | | GitHub Copilot CLI | `copilot_cli` | | Command Code | `commandcode` | +| Qwen Code | `qwen_code` | | VS Code | `vscode` | | Grok Build | `grok_build` | | OMP | `omp` | +For Qwen Code, setup registers `rea` in the `mcpServers` table of the +user-level `~/.qwen/settings.json`, or `$QWEN_HOME/settings.json` when configured. +Setup and doctor follow Qwen Code's tilde and working-directory-relative home +overrides. Qwen Code also discovers personal skills in `~/.agents/skills`, +where setup installs the bundled workflow. + For OMP, setup writes a `type: "stdio"` entry to the user-level `~/.omp/agent/mcp.json`. It follows `PI_CONFIG_DIR`, an absolute `PI_CODING_AGENT_DIR`, and the profile selected by `OMP_PROFILE` or @@ -194,10 +201,10 @@ save verified paths for an existing Ghidra installation. The bundled skill is installed where each selected client discovers personal skills: Claude Code uses `~/.claude/skills` (or -`$CLAUDE_CONFIG_DIR/skills` when configured), while other supported clients -use the shared `~/.agents/skills` directory. A mixed selection plans both -paths. Selecting the skill without a client uses the shared directory. Setup -leaves existing skill copies in other locations untouched. +`$CLAUDE_CONFIG_DIR/skills` when configured), while other supported clients, +including Qwen Code, use the shared `~/.agents/skills` directory. A mixed selection +plans the relevant paths. Selecting the skill without a client uses the shared +directory. Setup leaves existing skill copies in other locations untouched. `doctor --skill --json` verifies the selected copies against the bundled instructions and references. Consumers should use `identity.skill.state`, diff --git a/scripts/verify-package-environment.mjs b/scripts/verify-package-environment.mjs index f9ee010af..1a97cfbab 100644 --- a/scripts/verify-package-environment.mjs +++ b/scripts/verify-package-environment.mjs @@ -85,6 +85,7 @@ export async function verifyPackageEnvironment({ PI_CODING_AGENT_DIR: undefined, PI_CONFIG_DIR: undefined, PI_PROFILE: undefined, + QWEN_HOME: undefined, OPENCODE_CONFIG: undefined, XDG_CONFIG_HOME: join(home, ".config"), PATH: `${fakeBin}:${process.env.PATH ?? ""}`, diff --git a/src/application/ClientRegistrationStatus.ts b/src/application/ClientRegistrationStatus.ts index a657f1df4..1f5a12473 100644 --- a/src/application/ClientRegistrationStatus.ts +++ b/src/application/ClientRegistrationStatus.ts @@ -91,6 +91,7 @@ export const readClientRegistrationStatuses = async ( PI_CODING_AGENT_DIR: options.environment.PI_CODING_AGENT_DIR, PI_CONFIG_DIR: options.environment.PI_CONFIG_DIR, PI_PROFILE: options.environment.PI_PROFILE, + QWEN_HOME: options.environment.QWEN_HOME, SAND_DATA_ROOT: options.environment.SAND_DATA_ROOT, XDG_CONFIG_HOME: options.environment.XDG_CONFIG_HOME, }, diff --git a/src/application/SupportedClients.ts b/src/application/SupportedClients.ts index 97467a227..52f5577ca 100644 --- a/src/application/SupportedClients.ts +++ b/src/application/SupportedClients.ts @@ -1,4 +1,4 @@ -import { isAbsolute, join } from "node:path"; +import { isAbsolute, join, resolve } from "node:path"; import { lstatSync } from "node:fs"; /** One supported client configuration location. */ @@ -35,6 +35,7 @@ interface ClientPathContext { readonly PI_CODING_AGENT_DIR?: string | undefined; readonly PI_CONFIG_DIR?: string | undefined; readonly PI_PROFILE?: string | undefined; + readonly QWEN_HOME?: string | undefined; readonly SAND_DATA_ROOT?: string | undefined; readonly XDG_CONFIG_HOME?: string | undefined; }; @@ -85,6 +86,25 @@ const claudeCodeMarkerDirectory = ({ home, env }: ClientPathContext): string => const codexDirectory = ({ home, env }: ClientPathContext): string => env.CODEX_HOME ?? join(home, ".codex"); +/** Match Qwen Code's home override, including tilde and cwd-relative paths. */ +const qwenCodeDirectory = ({ home, env }: ClientPathContext): string => { + const override = env.QWEN_HOME; + if (!override) return join(home, ".qwen"); + const expanded = + override === "~" + ? home + : override.startsWith("~/") || override.startsWith("~\\") + ? join( + home, + ...override + .slice(2) + .split(/[/\\]+/) + .filter(Boolean), + ) + : override; + return isAbsolute(expanded) ? expanded : resolve(expanded); +}; + const grokDirectory = ({ home, env }: ClientPathContext): string => env.GROK_HOME ?? join(home, ".grok"); @@ -272,6 +292,14 @@ export const SUPPORTED_CLIENT_DEFINITIONS = [ markerPath: commandCodeDirectory, format: "commandcode", }, + { + name: "qwen_code", + displayName: "Qwen Code", + configPath: (context: ClientPathContext) => + join(qwenCodeDirectory(context), "settings.json"), + markerPath: qwenCodeDirectory, + format: "json", + }, { name: "vscode", displayName: "VS Code", @@ -323,6 +351,7 @@ export const supportedClients = ( PI_CODING_AGENT_DIR: process.env.PI_CODING_AGENT_DIR, PI_CONFIG_DIR: process.env.PI_CONFIG_DIR, PI_PROFILE: process.env.PI_PROFILE, + QWEN_HOME: process.env.QWEN_HOME, SAND_DATA_ROOT: process.env.SAND_DATA_ROOT, XDG_CONFIG_HOME: process.env.XDG_CONFIG_HOME, }, diff --git a/tests/boundary/filesystem/clientLifecycle.test.ts b/tests/boundary/filesystem/clientLifecycle.test.ts index 88eab9953..297787a10 100644 --- a/tests/boundary/filesystem/clientLifecycle.test.ts +++ b/tests/boundary/filesystem/clientLifecycle.test.ts @@ -59,6 +59,7 @@ describe("client configuration filesystem lifecycle", () => { "antigravity", "copilot_cli", "commandcode", + "qwen_code", "vscode", "grok_build", "omp", diff --git a/tests/boundary/filesystem/qwenClientConfiguration.test.ts b/tests/boundary/filesystem/qwenClientConfiguration.test.ts new file mode 100644 index 000000000..0fae29640 --- /dev/null +++ b/tests/boundary/filesystem/qwenClientConfiguration.test.ts @@ -0,0 +1,183 @@ +import { access, mkdir, readFile, writeFile } from "node:fs/promises"; +import { join, resolve } from "node:path"; + +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { parse as parseJsonc } from "jsonc-parser"; + +import { readClientRegistrationStatuses } from "../../../src/application/ClientRegistrationStatus.js"; +import { configureClientConfiguration } from "../../../src/application/SetupClientConfiguration.js"; +import { systemSetupHost } from "../../../src/application/SetupHost.js"; +import { supportedClients } from "../../../src/application/SupportedClients.js"; +import { systemUninstallHost } from "../../../src/application/Uninstall.js"; +import { PRODUCT_IDENTITY } from "../../../src/identity.js"; +import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { + clearClientLocationEnvironment, + NPX_REGISTRATION_COMMAND, +} from "../../fixtures/clientEnvironment.js"; + +const command = NPX_REGISTRATION_COMMAND; + +beforeEach(clearClientLocationEnvironment); +afterEach(() => vi.unstubAllEnvs()); + +const qwenPath = ( + home: string, + platform: NodeJS.Platform, + env: Parameters[2] = {}, +) => + supportedClients(home, platform, env).find( + ({ name }) => name === "qwen_code", + ); + +describe("Qwen Code configuration paths", () => { + it("resolves the user settings file and marker directory", () => { + expect(qwenPath("/home/a", "linux")).toEqual({ + name: "qwen_code", + displayName: "Qwen Code", + configPath: join("/home/a", ".qwen", "settings.json"), + markerPath: join("/home/a", ".qwen"), + format: "json", + }); + expect(qwenPath("/Users/a", "darwin")?.configPath).toBe( + join("/Users/a", ".qwen", "settings.json"), + ); + }); + + it.each([ + ["", join("/home/a", ".qwen")], + ["~", "/home/a"], + ["~/profiles/work", join("/home/a", "profiles", "work")], + ["~\\profiles\\work", join("/home/a", "profiles", "work")], + ["profiles/work", resolve("profiles/work")], + [" profile ", resolve(" profile ")], + ["$PROFILE", resolve("$PROFILE")], + ])("matches Qwen's QWEN_HOME resolution for %j", (override, directory) => { + vi.stubEnv("QWEN_HOME", override); + const client = qwenPath("/home/a", process.platform, { + QWEN_HOME: override, + }); + expect( + supportedClients("/home/a").find(({ name }) => name === "qwen_code"), + ).toEqual(client); + expect(client).toMatchObject({ + configPath: join(directory, "settings.json"), + markerPath: directory, + }); + }); +}); + +describe("Qwen Code client lifecycle", () => { + const qwenClient = async () => { + const home = await createTestTempDirectory("rea-qwen-"); + const client = qwenPath(home, process.platform, {}); + if (client?.markerPath === undefined) + throw new Error("missing Qwen Code client"); + await mkdir(client.markerPath, { recursive: true }); + return { home, client }; + }; + + it("registers rea in mcpServers while preserving unrelated settings and comments", async () => { + const { home, client } = await qwenClient(); + await writeFile( + client.configPath, + `{ + // Keep this note. + "model": { "name": "qwen3-coder-plus" }, + "mcpServers": { "other": { "command": "other-server" } } +} +`, + ); + expect( + (await configureClientConfiguration(client, {}, command)).status, + ).toBe("configured"); + const text = await readFile(client.configPath, "utf8"); + expect(text).toContain("// Keep this note."); + expect(parseJsonc(text)).toEqual({ + model: { name: "qwen3-coder-plus" }, + mcpServers: { + other: { command: "other-server" }, + rea: { command: "npx", args: command.slice(1) }, + }, + }); + expect(await configureClientConfiguration(client, {}, command)).toEqual({ + status: "unchanged", + }); + expect((await systemUninstallHost(home).removeClient(client)).status).toBe( + "removed", + ); + const removedText = await readFile(client.configPath, "utf8"); + const removed = parseJsonc(removedText); + expect(removed).toEqual({ + model: { name: "qwen3-coder-plus" }, + mcpServers: { other: { command: "other-server" } }, + }); + expect(removedText).toContain("// Keep this note."); + }); + + it("reports a package-runner registration as aligned", async () => { + const { home, client } = await qwenClient(); + expect( + (await configureClientConfiguration(client, {}, command)).status, + ).toBe("configured"); + const entry = resolve("scripts/rea.mjs"); + const status = ( + await readClientRegistrationStatuses(home, entry, { environment: {} }) + ).find(({ client: name }) => name === "qwen_code"); + expect(status).toMatchObject({ state: "aligned" }); + }); +}); + +describe("Qwen Code profile setup", () => { + it.each([false, true])( + "installs and removes the shared skill with a custom home: %s", + async (customHome) => { + const home = await createTestTempDirectory("rea-qwen-profile-"); + const profile = join(home, customHome ? "qwen-profile" : ".qwen"); + const environment = { + HOME: home, + USERPROFILE: home, + ...(customHome ? { QWEN_HOME: profile } : {}), + }; + await mkdir(profile); + const setup = systemSetupHost(undefined, environment); + const client = (await setup.detectedClients()).find( + ({ name }) => name === "qwen_code", + ); + if (client === undefined) throw new Error("missing Qwen Code client"); + expect(client.configPath).toBe(join(profile, "settings.json")); + expect(await setup.configureClient(client, {}, command)).toEqual({ + status: "configured", + }); + expect(await setup.installSkill([client.name])).toBe("installed"); + const skill = join(home, ".agents", "skills", PRODUCT_IDENTITY.skillName); + expect(await readFile(join(skill, "SKILL.md"), "utf8")).toContain( + "reverse-engineer-anything", + ); + expect(await setup.clientNeedsConfigure(client, {}, command)).toBe(false); + expect(await setup.skillNeedsInstall([client.name])).toBe(false); + expect(await setup.installSkill([client.name])).toBe("unchanged"); + expect( + ( + await readClientRegistrationStatuses( + home, + resolve("scripts/rea.mjs"), + { environment }, + ) + ).find(({ client: name }) => name === "qwen_code"), + ).toMatchObject({ state: "aligned" }); + const uninstall = systemUninstallHost(home, undefined, environment); + const registered = (await uninstall.clients()).find( + ({ name }) => name === "qwen_code", + ); + expect(registered).toEqual(client); + expect((await uninstall.removeClient(client)).status).toBe("removed"); + expect((await uninstall.removeSkill()).status).toBe("removed"); + await expect(access(skill)).rejects.toMatchObject({ code: "ENOENT" }); + if (customHome) + await expect(access(join(home, ".qwen"))).rejects.toMatchObject({ + code: "ENOENT", + }); + }, + ); +}); diff --git a/tests/fixtures/clientEnvironment.ts b/tests/fixtures/clientEnvironment.ts index 79961e49d..0db5a69ec 100644 --- a/tests/fixtures/clientEnvironment.ts +++ b/tests/fixtures/clientEnvironment.ts @@ -22,6 +22,7 @@ export const CLIENT_LOCATION_ENVIRONMENT = [ "PI_CODING_AGENT_DIR", "PI_CONFIG_DIR", "PI_PROFILE", + "QWEN_HOME", "SAND_DATA_ROOT", "XDG_CONFIG_HOME", ] as const;