Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(setup): honor config roots and display terminal dry-run plans

morluto23971376158e
diff --git a/src/application/SupportedClients.ts b/src/application/SupportedClients.ts
index 18c3480d9..488dda49d 100644
--- a/src/application/SupportedClients.ts
+++ b/src/application/SupportedClients.ts
@@ -75,6 +75,10 @@ interface ClientDefinition {
) => NonNullable<SetupClient["geminiSettings"]>;
}
+/** XDG treats an empty config-home value as unset. */
+const xdgConfigHome = ({ home, env }: ClientPathContext): string =>
+ env.XDG_CONFIG_HOME || join(home, ".config");
+
const vscodeUserDirectory = ({
home,
platform,
@@ -88,7 +92,7 @@ const vscodeUserDirectory = ({
);
if (platform === "darwin")
return join(home, "Library", "Application Support", "Code", "User");
- return join(env.XDG_CONFIG_HOME ?? join(home, ".config"), "Code", "User");
+ return join(xdgConfigHome({ home, platform, env }), "Code", "User");
};
const traeUserDirectory = ({
@@ -104,7 +108,7 @@ const traeUserDirectory = ({
);
if (platform === "darwin")
return join(home, "Library", "Application Support", "Trae", "User");
- return join(env.XDG_CONFIG_HOME ?? join(home, ".config"), "Trae", "User");
+ return join(xdgConfigHome({ home, platform, env }), "Trae", "User");
};
const claudeDesktopDirectory = ({
@@ -115,7 +119,7 @@ const claudeDesktopDirectory = ({
if (platform === "win32")
return join(env.APPDATA ?? join(home, "AppData", "Roaming"), "Claude");
if (platform === "linux")
- return join(env.XDG_CONFIG_HOME ?? join(home, ".config"), "Claude");
+ return join(xdgConfigHome({ home, platform, env }), "Claude");
return join(home, "Library", "Application Support", "Claude");
};
@@ -268,19 +272,13 @@ const openCodeOverrideDirectory = (
const opencodeDirectory = (context: ClientPathContext): string =>
openCodeOverrideDirectory(context.env) ??
- join(
- context.env.XDG_CONFIG_HOME ?? join(context.home, ".config"),
- "opencode",
- );
+ join(xdgConfigHome(context), "opencode");
/** OpenCode loads global JSON before JSONC, then explicit file and directory overrides. */
const openCodeConfigurationPaths = (
context: ClientPathContext,
): readonly string[] => {
- const directory = join(
- context.env.XDG_CONFIG_HOME ?? join(context.home, ".config"),
- "opencode",
- );
+ const directory = join(xdgConfigHome(context), "opencode");
const overrideDirectory = openCodeOverrideDirectory(context.env);
const paths = [
join(directory, "config.json"),
diff --git a/src/cli/interactiveSetup.ts b/src/cli/interactiveSetup.ts
index 9fcdf3d18..6d19ae6eb 100644
--- a/src/cli/interactiveSetup.ts
+++ b/src/cli/interactiveSetup.ts
@@ -82,6 +82,13 @@ export const renderSetupProgress = (event: SetupProgressEvent): void => {
writeLine(`${symbol} ${event.label}${suffix}`);
};
+/** Show the resolved dry-run plan to a human at an interactive terminal. */
+export const renderSetupDryRun = (actions: readonly SetupAction[]): void => {
+ intro("REA setup plan", promptStreams);
+ renderPreflight(actions);
+ outro("Dry run complete. No changes were made.", promptStreams);
+};
+
/** Finish an interactive setup journey without exposing the full doctor catalog. */
export const renderInteractiveSetupResult = (
result: SetupResult,
diff --git a/src/cli/setupCommands.ts b/src/cli/setupCommands.ts
index 15caac321..483de20cb 100644
--- a/src/cli/setupCommands.ts
+++ b/src/cli/setupCommands.ts
@@ -11,6 +11,7 @@ import { homeDirectoryFromEnvironment } from "../config/homeDirectory.js";
import { isUpdateFailure } from "../application/UpdateFailure.js";
import {
confirmInteractiveSetup,
+ renderSetupDryRun,
renderInteractiveSetupResult,
renderSetupProgress,
} from "./interactiveSetup.js";
@@ -225,6 +226,8 @@ const runSetupCommand = async (
: undefined,
);
if (interactive) renderInteractiveSetupResult(result, environment);
+ else if (options.dryRun && !input.formatExplicit && hasInteractiveTerminal())
+ renderSetupDryRun(result.plannedActions);
return result;
};
@@ -282,6 +285,9 @@ const setupIsInteractive = (
!options.yes &&
!options.dryRun &&
!formatExplicit &&
+ hasInteractiveTerminal();
+
+const hasInteractiveTerminal = (): boolean =>
process.stdin.isTTY === true &&
process.stdout.isTTY === true &&
process.stderr.isTTY === true;
diff --git a/tests/boundary/cli/cliSetup.test.ts b/tests/boundary/cli/cliSetup.test.ts
index 742a3a6bc..38bc24bb3 100644
--- a/tests/boundary/cli/cliSetup.test.ts
+++ b/tests/boundary/cli/cliSetup.test.ts
@@ -1,5 +1,6 @@
import { execFile } from "node:child_process";
-import { rm } from "node:fs/promises";
+import { access, rm } from "node:fs/promises";
+import { join } from "node:path";
import { promisify } from "node:util";
import { spawn } from "@lydell/node-pty";
@@ -73,6 +74,61 @@ const clientStates = [
const agentActions = actions.filter(({ kind }) => kind !== "install_hopper");
+describe("TTY setup dry run", () => {
+ it("prints the plan and no-mutation notice for a TTY dry run", async () => {
+ const home = await createTestTempDirectory("rea-cli-setup-dry-run-");
+ const terminal = spawn(
+ process.execPath,
+ [
+ "scripts/rea.mjs",
+ "setup",
+ "--dry-run",
+ "--client",
+ "codex",
+ "--skill=false",
+ ],
+ {
+ cwd: process.cwd(),
+ env: {
+ ...process.env,
+ HOME: home,
+ USERPROFILE: home,
+ XDG_CONFIG_HOME: join(home, ".config"),
+ REA_LOG_LEVEL: "silent",
+ NO_COLOR: "1",
+ },
+ name: "xterm-256color",
+ cols: 120,
+ rows: 40,
+ },
+ );
+ let output = "";
+ terminal.onData((data) => {
+ output += data;
+ });
+ const exitCode = await new Promise<number>((resolvePromise, reject) => {
+ const timeout = setTimeout(() => {
+ terminal.kill();
+ reject(new Error(`TTY dry run timed out after output:\n${output}`));
+ }, 15_000);
+ terminal.onExit(({ exitCode: code }) => {
+ clearTimeout(timeout);
+ resolvePromise(code);
+ });
+ });
+
+ expect(exitCode, output).toBe(0);
+ expect(output).toContain("CREATE Codex");
+ expect(output).toContain(join(home, ".codex/config.toml"));
+ expect(output).toContain("Dry run complete. No changes were made.");
+ await expect(
+ access(join(home, ".codex/config.toml")),
+ ).rejects.toMatchObject({
+ code: "ENOENT",
+ });
+ });
+});
+
describe("interactive setup journey", () => {
it("shows detected and absent clients without preselecting detected clients", async () => {
const result = await runJourney(
diff --git a/tests/boundary/filesystem/clientConfigurationDialects.test.ts b/tests/boundary/filesystem/clientConfigurationDialects.test.ts
index 9dd850d8c..ce867aab4 100644
--- a/tests/boundary/filesystem/clientConfigurationDialects.test.ts
+++ b/tests/boundary/filesystem/clientConfigurationDialects.test.ts
@@ -37,6 +37,22 @@ const getClients = (home: string) =>
);
describe("additional client configuration dialects", () => {
+ it("treats an empty XDG config home as unset for OpenCode setup", async () => {
+ const home = await createTestTempDirectory("rea-opencode-empty-xdg-");
+ const client = supportedClients(home, "linux", {
+ XDG_CONFIG_HOME: "",
+ }).find(({ name }) => name === "opencode");
+ const expectedPath = join(home, ".config/opencode/opencode.json");
+ if (client === undefined) throw new Error("missing opencode client");
+
+ expect(client.configPath).toBe(expectedPath);
+ expect(client.configPaths).toContain(expectedPath);
+ expect(
+ await configureClientConfiguration(client, {}, command),
+ ).toMatchObject({ status: "configured" });
+ expect(await readFile(expectedPath, "utf8")).toContain('"mcp"');
+ });
+
it.each([
"opencode",
"antigravity",