feat(cli): improve setup onboarding
This commit is contained in:
@@ -0,0 +1,254 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { spawn } from "@lydell/node-pty";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
const decisionMarker = "REA_SETUP_DECISION:";
|
||||
|
||||
const actions = [
|
||||
{
|
||||
id: "configure_client:codex",
|
||||
kind: "configure_client",
|
||||
label: "Codex",
|
||||
target: "/isolated/.codex/config.toml",
|
||||
detail: "Add the REA MCP registration for Codex.",
|
||||
external: false,
|
||||
operation: "create",
|
||||
},
|
||||
{
|
||||
id: "install_skill",
|
||||
kind: "install_skill",
|
||||
label: "REA reverse-engineering skill",
|
||||
target: "/isolated/.agents/skills/reverse-engineering/SKILL.md",
|
||||
detail: "Install the bundled reverse-engineering skill.",
|
||||
external: false,
|
||||
operation: "install",
|
||||
},
|
||||
{
|
||||
id: "install_hopper",
|
||||
kind: "install_hopper",
|
||||
label: "Hopper deep-analysis provider",
|
||||
target: "/isolated/Applications/Hopper Disassembler.app",
|
||||
detail: "Install the verified Hopper package.",
|
||||
external: true,
|
||||
operation: "install",
|
||||
},
|
||||
] as const;
|
||||
|
||||
describe("interactive setup journey", () => {
|
||||
it("leads with value, detected targets, modality labels, and durable key help", async () => {
|
||||
const result = await runJourney([step("Choose a setup", "\u0003")]);
|
||||
|
||||
expect(result.output).toContain(
|
||||
"Understand local apps and binaries from your coding agent.",
|
||||
);
|
||||
expect(result.output).toContain(
|
||||
"Trace how a feature works with local evidence.",
|
||||
);
|
||||
expect(result.output).toContain("Detected Codex");
|
||||
expect(result.output).toContain("Codex · MCP · create");
|
||||
expect(result.output).toContain("Hopper deep-analysis provider (provider)");
|
||||
expect(result.output).toContain("REA reverse-engineering skill (skill)");
|
||||
expect(result.output).toContain(
|
||||
"Keys: ↑/↓ navigate · Space toggle · Enter confirm · Ctrl-C cancel",
|
||||
);
|
||||
expect(result.decision.approved).toBe(false);
|
||||
});
|
||||
|
||||
it("offers recommended, custom, and no-thanks intent before choosing targets", async () => {
|
||||
const result = await runJourney([
|
||||
step("Choose a setup", "\u001b[B\u001b[B\r"),
|
||||
]);
|
||||
|
||||
expect(result.output).toContain("Set up all available capabilities");
|
||||
expect(result.output).toContain("recommended · 3 changes");
|
||||
expect(result.output).toContain("Customize setup");
|
||||
expect(result.output).toContain("No thanks");
|
||||
expect(result.output).not.toContain("Ready to review");
|
||||
expect(result.decision).toMatchObject({ approved: false });
|
||||
});
|
||||
|
||||
it("lets custom mode reach the modality-labelled target picker and cancel safely", async () => {
|
||||
const result = await runJourney([
|
||||
step("Choose a setup", "\u001b[B\r"),
|
||||
step("Choose what REA should configure", "\u0003"),
|
||||
]);
|
||||
|
||||
expect(result.output).toContain("Choose what REA should configure");
|
||||
expect(result.output).toContain("Codex (MCP)");
|
||||
expect(result.output).toContain("Hopper deep-analysis provider (provider)");
|
||||
expect(result.output).toContain("Setup cancelled. No changes were made.");
|
||||
expect(result.decision.approved).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps the recommended path subject to a default-No exact preflight", async () => {
|
||||
const result = await runJourney([
|
||||
step("Choose a setup", "\r"),
|
||||
step("Apply these 3 changes?", "\r"),
|
||||
]);
|
||||
|
||||
expect(result.output).toContain("Ready to review");
|
||||
expect(result.output).toContain("CREATE Codex");
|
||||
expect(result.output).toContain("/isolated/.codex/config.toml");
|
||||
expect(result.output).toContain("No, cancel");
|
||||
expect(result.output).toContain("Setup cancelled. No changes were made.");
|
||||
expect(result.decision).toEqual({
|
||||
approved: false,
|
||||
selectedActionIds: actions.map(({ id }) => id),
|
||||
});
|
||||
});
|
||||
|
||||
it("frames completion around the capabilities that are now ready", async () => {
|
||||
const { stderr } = await execute(
|
||||
process.execPath,
|
||||
[
|
||||
"--input-type=module",
|
||||
"--eval",
|
||||
[
|
||||
'import { renderInteractiveSetupResult } from "./dist/cliSetup.js";',
|
||||
"renderInteractiveSetupResult({",
|
||||
' status: "ready",',
|
||||
" plannedActions: [],",
|
||||
" appliedActions: [],",
|
||||
' clients: { codex: { status: "configured" } },',
|
||||
" doctor: {",
|
||||
" healthy: true,",
|
||||
' hopperPath: "/Applications/Hopper",',
|
||||
" checks: [],",
|
||||
' providerInspections: [{ id: "ghidra", available: true }],',
|
||||
' identity: { skill: { state: "aligned" }, registrations: [{ client: "codex", state: "aligned" }] },',
|
||||
" },",
|
||||
"});",
|
||||
].join("\n"),
|
||||
],
|
||||
{
|
||||
cwd: process.cwd(),
|
||||
env: { ...process.env, NO_COLOR: "1" },
|
||||
},
|
||||
);
|
||||
|
||||
expect(stderr).toContain("What you can do now");
|
||||
expect(stderr).toContain("Deep analysis: Hopper and Ghidra");
|
||||
expect(stderr).toContain("Agent access: Codex");
|
||||
expect(stderr).toContain("Guided reverse-engineering workflows: installed");
|
||||
expect(stderr).toContain("CLI: rea analyze /path/to/app");
|
||||
expect(stderr).toContain(
|
||||
'Try in Codex: "Use REA to explain how a feature works in /path/to/app."',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
interface JourneyStep {
|
||||
readonly prompt: string;
|
||||
readonly input: string;
|
||||
}
|
||||
|
||||
interface JourneyResult {
|
||||
readonly output: string;
|
||||
readonly decision: {
|
||||
readonly approved: boolean;
|
||||
readonly selectedActionIds: readonly string[];
|
||||
};
|
||||
}
|
||||
|
||||
const step = (prompt: string, input: string): JourneyStep => ({
|
||||
prompt,
|
||||
input,
|
||||
});
|
||||
|
||||
const runJourney = async (
|
||||
steps: readonly JourneyStep[],
|
||||
): Promise<JourneyResult> => {
|
||||
const isolatedHome = await mkdtemp(join(tmpdir(), "rea-cli-setup-test-"));
|
||||
const script = [
|
||||
'import { confirmInteractiveSetup } from "./dist/cliSetup.js";',
|
||||
`const actions = ${JSON.stringify(actions)};`,
|
||||
"const decision = await confirmInteractiveSetup(actions, false);",
|
||||
`process.stdout.write(${JSON.stringify(`\n${decisionMarker}`)} + JSON.stringify(decision) + "\\n");`,
|
||||
].join("\n");
|
||||
|
||||
return new Promise<JourneyResult>((resolvePromise, reject) => {
|
||||
let output = "";
|
||||
let nextStep = 0;
|
||||
let settled = false;
|
||||
const terminal = spawn(
|
||||
process.execPath,
|
||||
["--input-type=module", "--eval", script],
|
||||
{
|
||||
cwd: process.cwd(),
|
||||
env: {
|
||||
...process.env,
|
||||
HOME: isolatedHome,
|
||||
NO_COLOR: "1",
|
||||
TERM: "xterm-256color",
|
||||
},
|
||||
name: "xterm-256color",
|
||||
cols: 120,
|
||||
rows: 40,
|
||||
},
|
||||
);
|
||||
const timeout = setTimeout(() => {
|
||||
terminal.kill();
|
||||
finish(new Error(`Timed out after output:\n${output}`));
|
||||
}, 10_000);
|
||||
|
||||
terminal.onData((data) => {
|
||||
output += data;
|
||||
const pending = steps[nextStep];
|
||||
if (pending !== undefined && output.includes(pending.prompt)) {
|
||||
nextStep += 1;
|
||||
terminal.write(pending.input);
|
||||
}
|
||||
});
|
||||
terminal.onExit(({ exitCode }) => {
|
||||
if (exitCode !== 0) {
|
||||
finish(
|
||||
new Error(`Setup journey exited ${String(exitCode)}:\n${output}`),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (nextStep !== steps.length) {
|
||||
finish(new Error(`Setup journey missed an interaction:\n${output}`));
|
||||
return;
|
||||
}
|
||||
const markerIndex = output.lastIndexOf(decisionMarker);
|
||||
if (markerIndex === -1) {
|
||||
finish(new Error(`Setup journey returned no decision:\n${output}`));
|
||||
return;
|
||||
}
|
||||
const serialized = output
|
||||
.slice(markerIndex + decisionMarker.length)
|
||||
.split(/\r?\n/u, 1)[0];
|
||||
if (serialized === undefined) {
|
||||
finish(
|
||||
new Error(`Setup journey returned an empty decision:\n${output}`),
|
||||
);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
finish(undefined, {
|
||||
output,
|
||||
decision: JSON.parse(serialized) as JourneyResult["decision"],
|
||||
});
|
||||
} catch (cause: unknown) {
|
||||
finish(cause instanceof Error ? cause : new Error(String(cause)));
|
||||
}
|
||||
});
|
||||
|
||||
function finish(error?: Error, result?: JourneyResult): void {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
clearTimeout(timeout);
|
||||
void rm(isolatedHome, { recursive: true, force: true }).finally(() => {
|
||||
if (error !== undefined) reject(error);
|
||||
else if (result !== undefined) resolvePromise(result);
|
||||
else reject(new Error("Setup journey completed without a result"));
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -88,15 +88,21 @@ describe("doctor", () => {
|
||||
});
|
||||
});
|
||||
it("detects a manual configured Hopper before Homebrew", async () => {
|
||||
let brewProbes = 0;
|
||||
const result = await runDoctor(
|
||||
undefined,
|
||||
host({
|
||||
configuredHopperPath: "/manual/Hopper",
|
||||
executable: (path) => Promise.resolve(path === "/manual/Hopper"),
|
||||
brewHopperPath: () => {
|
||||
brewProbes += 1;
|
||||
return Promise.resolve(undefined);
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(result.hopperPath).toBe("/manual/Hopper");
|
||||
expect(result.healthy).toBe(true);
|
||||
expect(brewProbes).toBe(0);
|
||||
});
|
||||
|
||||
it("reports optional BYO ilspycmd diagnostics only when configured", async () => {
|
||||
|
||||
@@ -3,6 +3,7 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
installLinuxHopper,
|
||||
linuxHopperInstallDisclosure,
|
||||
linuxPackageManagerCommands,
|
||||
linuxSharedLibrariesAvailable,
|
||||
parseLinuxDistribution,
|
||||
@@ -92,6 +93,18 @@ describe("Linux Hopper host classification", () => {
|
||||
});
|
||||
|
||||
describe("Linux Hopper installation", () => {
|
||||
it("discloses the exact download, integrity evidence, and privileged command", () => {
|
||||
expect(linuxHopperInstallDisclosure("deb", false)).toEqual({
|
||||
downloadUrl:
|
||||
"https://www.hopperapp.com:443/downloader/public/Hopper-6.4.2-Linux-demo.deb",
|
||||
expectedBytes: 35_755_772,
|
||||
expectedSha1: "e4f79dff602648a8ff4a88b773875b6bfac0dc65",
|
||||
commands: [
|
||||
"pkexec apt-get install -y <verified-hopper.deb> xvfb xauth python3 libx11-6 libxtst6",
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
["deb", "apt-get"],
|
||||
["rpm", "dnf"],
|
||||
|
||||
@@ -4,6 +4,7 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
installMacHopper,
|
||||
macHopperInstallDisclosure,
|
||||
type MacHopperInstallHost,
|
||||
} from "../src/application/MacHopper.js";
|
||||
|
||||
@@ -74,6 +75,18 @@ class FakeMacHopperHost implements MacHopperInstallHost {
|
||||
}
|
||||
|
||||
describe("macOS Hopper installation", () => {
|
||||
it("discloses network and command boundaries before installation", () => {
|
||||
expect(macHopperInstallDisclosure).toMatchObject({
|
||||
networkOrigins: [
|
||||
"https://www.hopperapp.com/include/files-api.php?request=releases&public=true",
|
||||
"https://www.hopperapp.com:443/downloader/public/",
|
||||
],
|
||||
});
|
||||
expect(macHopperInstallDisclosure.commands).toContain(
|
||||
"hdiutil attach -readonly -nobrowse -mountpoint <private-mount> <verified-hopper.dmg>",
|
||||
);
|
||||
});
|
||||
|
||||
it("installs, verifies, opens, and cleans the official package", async () => {
|
||||
const host = new FakeMacHopperHost();
|
||||
await expect(installMacHopper({}, host)).resolves.toEqual({
|
||||
|
||||
@@ -2,11 +2,13 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
runSetup,
|
||||
type ClientConfigurationInspection,
|
||||
type ClientConfigurationResult,
|
||||
type SetupClient,
|
||||
type SetupHost,
|
||||
type SetupOptions,
|
||||
type SetupHopperInstallResult,
|
||||
type SetupProgressEvent,
|
||||
type SetupProviderEnvironment,
|
||||
} from "../src/application/Setup.js";
|
||||
import type { DoctorCheck } from "../src/application/Doctor.js";
|
||||
@@ -24,6 +26,7 @@ class FakeSetupHost implements SetupHost {
|
||||
skill: "installed" | "unchanged" | "failed" = "installed";
|
||||
clients: readonly SetupClient[] = [];
|
||||
clientResults = new Map<string, ClientConfigurationResult>();
|
||||
clientInspections = new Map<string, ClientConfigurationInspection>();
|
||||
hopperInstalls = 0;
|
||||
hopperReplaceRequests: boolean[] = [];
|
||||
configurations = 0;
|
||||
@@ -91,6 +94,12 @@ class FakeSetupHost implements SetupHost {
|
||||
this.clientResults.get(client.name)?.status !== "unchanged",
|
||||
);
|
||||
};
|
||||
inspectClientConfiguration = (
|
||||
client: SetupClient,
|
||||
): Promise<ClientConfigurationInspection> =>
|
||||
Promise.resolve(
|
||||
this.clientInspections.get(client.name) ?? { status: "update" },
|
||||
);
|
||||
skillNeedsInstall = (): Promise<boolean> =>
|
||||
Promise.resolve(this.skill !== "unchanged");
|
||||
installSkill = (): Promise<"installed" | "unchanged" | "failed"> => {
|
||||
@@ -251,6 +260,41 @@ describe("setup workflow", () => {
|
||||
expect(host.hopperInstalls).toBe(0);
|
||||
});
|
||||
|
||||
it("reports append-only lifecycle progress for each selected action", async () => {
|
||||
const host = new FakeSetupHost();
|
||||
host.hopper = "/Applications/Hopper";
|
||||
host.clients = [
|
||||
{
|
||||
name: "codex",
|
||||
displayName: "Codex",
|
||||
configPath: "/codex.toml",
|
||||
},
|
||||
];
|
||||
const progress: SetupProgressEvent[] = [];
|
||||
await runSetup(
|
||||
{ ...options(true), onProgress: (event) => progress.push(event) },
|
||||
host,
|
||||
);
|
||||
expect(progress).toEqual([
|
||||
{ actionId: "configure_client:codex", label: "Codex", state: "started" },
|
||||
{
|
||||
actionId: "configure_client:codex",
|
||||
label: "Codex",
|
||||
state: "completed",
|
||||
},
|
||||
{
|
||||
actionId: "install_skill",
|
||||
label: "REA reverse-engineering skill",
|
||||
state: "started",
|
||||
},
|
||||
{
|
||||
actionId: "install_skill",
|
||||
label: "REA reverse-engineering skill",
|
||||
state: "completed",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("plans and propagates BYO Ghidra without installing software", async () => {
|
||||
const host = new FakeSetupHost("linux");
|
||||
host.distribution = {
|
||||
@@ -373,6 +417,98 @@ describe("setup workflow", () => {
|
||||
expect(host.configurations).toBe(0);
|
||||
});
|
||||
|
||||
it("blocks malformed client configuration before Hopper or file mutation", async () => {
|
||||
const host = new FakeSetupHost();
|
||||
host.clients = [
|
||||
{ name: "codex", displayName: "Codex", configPath: "/codex.toml" },
|
||||
];
|
||||
host.clientInspections.set("codex", {
|
||||
status: "invalid",
|
||||
remediation: "Repair the existing TOML.",
|
||||
});
|
||||
|
||||
const result = await runSetup(options(true, true), host);
|
||||
|
||||
expect(result.status).toBe("needs_human");
|
||||
expect(result.remediation).toBe("Codex: Repair the existing TOML.");
|
||||
expect(host.hopperInstalls).toBe(0);
|
||||
expect(host.configurations).toBe(0);
|
||||
expect(host.skillInstalls).toBe(0);
|
||||
});
|
||||
|
||||
it("blocks malformed configuration before unrelated writes with an existing provider", async () => {
|
||||
const host = new FakeSetupHost();
|
||||
host.hopper = "/Applications/Hopper";
|
||||
host.clients = [
|
||||
{
|
||||
name: "claude_desktop",
|
||||
displayName: "Claude Desktop",
|
||||
configPath: "/claude.json",
|
||||
},
|
||||
{ name: "cursor", displayName: "Cursor", configPath: "/cursor.json" },
|
||||
];
|
||||
host.clientInspections.set("claude_desktop", {
|
||||
status: "invalid",
|
||||
remediation: "Repair the existing JSON.",
|
||||
});
|
||||
|
||||
const result = await runSetup(options(true), host);
|
||||
|
||||
expect(result.status).toBe("needs_human");
|
||||
expect(result.remediation).toBe(
|
||||
"Claude Desktop: Repair the existing JSON.",
|
||||
);
|
||||
expect(host.configurations).toBe(0);
|
||||
expect(host.skillInstalls).toBe(0);
|
||||
});
|
||||
|
||||
it("plans a client update when Hopper installation changes its desired environment", async () => {
|
||||
const host = new FakeSetupHost();
|
||||
host.clients = [
|
||||
{ name: "codex", displayName: "Codex", configPath: "/codex.toml" },
|
||||
];
|
||||
host.clientInspections.set("codex", { status: "already_current" });
|
||||
|
||||
const result = await runSetup(options(false), host);
|
||||
|
||||
expect(
|
||||
result.plannedActions.map(({ id, operation }) => ({
|
||||
id,
|
||||
operation,
|
||||
})),
|
||||
).toContainEqual({
|
||||
id: "configure_client:codex",
|
||||
operation: "update",
|
||||
});
|
||||
expect(host.configurations).toBe(0);
|
||||
});
|
||||
|
||||
it("executes only actions selected by the interactive adapter", async () => {
|
||||
const host = new FakeSetupHost();
|
||||
host.hopper = "/Applications/Hopper";
|
||||
host.clients = [
|
||||
{ name: "codex", displayName: "Codex", configPath: "/codex.toml" },
|
||||
{ name: "cursor", displayName: "Cursor", configPath: "/cursor.json" },
|
||||
];
|
||||
|
||||
const result = await runSetup(
|
||||
{ ...options(false), structured: false },
|
||||
host,
|
||||
() =>
|
||||
Promise.resolve({
|
||||
approved: true,
|
||||
selectedActionIds: ["configure_client:codex"],
|
||||
}),
|
||||
);
|
||||
|
||||
expect(result.plannedActions.map(({ id }) => id)).toEqual([
|
||||
"configure_client:codex",
|
||||
]);
|
||||
expect(result.clients).toEqual({ codex: { status: "configured" } });
|
||||
expect(host.configurations).toBe(1);
|
||||
expect(host.skillInstalls).toBe(0);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[
|
||||
"path",
|
||||
|
||||
Reference in New Issue
Block a user