feat(cli): improve setup onboarding
This commit is contained in:
@@ -195,15 +195,16 @@ export const runDoctor = async (
|
||||
SYSTEM_LINUX_HOPPER,
|
||||
linuxHopperLauncherPath(homedir()),
|
||||
...(await host.manualHopperPaths()),
|
||||
await host.brewHopperPath(),
|
||||
].filter((value): value is string => value !== undefined)
|
||||
]
|
||||
: [host.configuredHopperPath];
|
||||
let hopperPath: string | undefined;
|
||||
for (const candidate of new Set(candidates))
|
||||
if (await host.executable(candidate)) {
|
||||
hopperPath = candidate;
|
||||
break;
|
||||
}
|
||||
let hopperPath = await firstExecutable(host, candidates);
|
||||
if (hopperPath === undefined && host.configuredHopperPath === undefined) {
|
||||
const brewCandidate = await host.brewHopperPath();
|
||||
hopperPath = await firstExecutable(
|
||||
host,
|
||||
brewCandidate === undefined ? [] : [brewCandidate],
|
||||
);
|
||||
}
|
||||
checks.push(
|
||||
check(
|
||||
"hopper",
|
||||
@@ -562,6 +563,15 @@ const uniqueLines = (value: string): string[] => [
|
||||
),
|
||||
];
|
||||
|
||||
const firstExecutable = async (
|
||||
host: DoctorHost,
|
||||
candidates: readonly string[],
|
||||
): Promise<string | undefined> => {
|
||||
for (const candidate of new Set(candidates))
|
||||
if (await host.executable(candidate)) return candidate;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const firstIlspyVersionLine = (value: string): string | undefined =>
|
||||
uniqueLines(value).find((line) => line.startsWith("ilspycmd:"));
|
||||
|
||||
|
||||
@@ -38,6 +38,32 @@ const SUPPORTED_RELEASES: Readonly<
|
||||
|
||||
export type LinuxPackageFamily = "deb" | "rpm" | "arch";
|
||||
|
||||
/** Exact stable external effects disclosed before a Linux Hopper installation. */
|
||||
export interface LinuxHopperInstallDisclosure {
|
||||
readonly downloadUrl: string;
|
||||
readonly expectedBytes: number;
|
||||
readonly expectedSha1: string;
|
||||
readonly commands: readonly string[];
|
||||
}
|
||||
|
||||
/** Describe the release and package-manager commands without downloading or writing. */
|
||||
export const linuxHopperInstallDisclosure = (
|
||||
family: LinuxPackageFamily,
|
||||
isRoot: boolean,
|
||||
): LinuxHopperInstallDisclosure => {
|
||||
const release = SUPPORTED_RELEASES[family];
|
||||
return {
|
||||
downloadUrl: release.filename,
|
||||
expectedBytes: Number(release.file_length),
|
||||
expectedSha1: release.file_hash,
|
||||
commands: linuxPackageManagerCommands(
|
||||
family,
|
||||
`<verified-hopper.${family}>`,
|
||||
isRoot,
|
||||
).map(({ executable, args }) => `${executable} ${args.join(" ")}`),
|
||||
};
|
||||
};
|
||||
|
||||
/** Parsed Linux distribution information used for support and package selection. */
|
||||
export interface LinuxDistribution {
|
||||
readonly id: string;
|
||||
|
||||
@@ -22,6 +22,17 @@ const DOWNLOAD_PREFIX = "https://www.hopperapp.com:443/downloader/public/";
|
||||
const MAX_PACKAGE_BYTES = 100_000_000;
|
||||
const BUNDLE_IDENTIFIER = "com.cryptic-apps.hopper-web-4";
|
||||
|
||||
/** Stable network and command effects disclosed before macOS Hopper setup. */
|
||||
export const macHopperInstallDisclosure = {
|
||||
networkOrigins: [RELEASES_URL, DOWNLOAD_PREFIX] as const,
|
||||
commands: [
|
||||
"hdiutil attach -readonly -nobrowse -mountpoint <private-mount> <verified-hopper.dmg>",
|
||||
"codesign --verify --deep --strict <mounted-hopper.app>",
|
||||
"ditto <mounted-hopper.app> <user-Applications-stage>",
|
||||
"open <installed-hopper.app>",
|
||||
] as const,
|
||||
};
|
||||
|
||||
/** Result of installing the official Hopper macOS application. */
|
||||
export type MacHopperInstallResult =
|
||||
| { readonly status: "installed"; readonly launcherPath: string }
|
||||
|
||||
+270
-24
@@ -66,6 +66,18 @@ export type ClientConfigurationResult =
|
||||
readonly status: "failed";
|
||||
readonly reason: "path" | "backup" | "write" | "readback";
|
||||
};
|
||||
|
||||
/** Read-only state used to block unsafe setup plans before any mutation. */
|
||||
export type ClientConfigurationInspection =
|
||||
| { readonly status: "already_current" }
|
||||
| {
|
||||
readonly status: "create" | "update";
|
||||
readonly backupPath?: string;
|
||||
}
|
||||
| {
|
||||
readonly status: "invalid";
|
||||
readonly remediation: string;
|
||||
};
|
||||
/**
|
||||
* Effects required by the idempotent setup workflow.
|
||||
* Implementations report interrupted installers as values: setup must not wait
|
||||
@@ -90,6 +102,11 @@ export interface SetupHost {
|
||||
providerEnvironment: SetupProviderEnvironment,
|
||||
command: readonly string[],
|
||||
): Promise<boolean>;
|
||||
inspectClientConfiguration?(
|
||||
client: SetupClient,
|
||||
providerEnvironment: SetupProviderEnvironment,
|
||||
command: readonly string[],
|
||||
): Promise<ClientConfigurationInspection>;
|
||||
skillNeedsInstall(): Promise<boolean>;
|
||||
installSkill(): Promise<"installed" | "unchanged" | "failed">;
|
||||
doctor(): Promise<Awaited<ReturnType<typeof runDoctor>>>;
|
||||
@@ -111,10 +128,17 @@ export interface SetupResult {
|
||||
|
||||
/** One concrete setup mutation disclosed before approval. */
|
||||
export interface SetupAction {
|
||||
readonly id: string;
|
||||
readonly kind: "install_hopper" | "configure_client" | "install_skill";
|
||||
readonly label: string;
|
||||
readonly target: string;
|
||||
readonly detail: string;
|
||||
readonly external: boolean;
|
||||
readonly operation: "create" | "update" | "install";
|
||||
readonly backupPath?: string;
|
||||
readonly networkOrigins?: readonly string[];
|
||||
readonly commands?: readonly string[];
|
||||
readonly integrity?: string;
|
||||
}
|
||||
|
||||
/** Explicit authorization supplied by an interactive or unattended CLI adapter. */
|
||||
@@ -122,12 +146,30 @@ export interface SetupOptions {
|
||||
readonly approved: boolean;
|
||||
readonly installHopper: boolean;
|
||||
readonly structured: boolean;
|
||||
readonly proposeHopper?: boolean;
|
||||
readonly clientIds?: readonly string[];
|
||||
readonly installSkill?: boolean;
|
||||
readonly onProgress?: (event: SetupProgressEvent) => void;
|
||||
}
|
||||
|
||||
/** One settled or active setup operation projected to the interactive adapter. */
|
||||
export interface SetupProgressEvent {
|
||||
readonly actionId: string;
|
||||
readonly label: string;
|
||||
readonly state: "started" | "completed" | "warning" | "failed";
|
||||
readonly detail?: string;
|
||||
}
|
||||
|
||||
/** Interactive selection and final consent returned by the CLI adapter. */
|
||||
export interface SetupConfirmationDecision {
|
||||
readonly approved: boolean;
|
||||
readonly selectedActionIds: readonly string[];
|
||||
}
|
||||
|
||||
/** Adapter-owned interactive confirmation for a fully discovered setup plan. */
|
||||
export type SetupConfirmation = (
|
||||
actions: readonly SetupAction[],
|
||||
) => Promise<boolean>;
|
||||
) => Promise<boolean | SetupConfirmationDecision>;
|
||||
|
||||
/**
|
||||
* Install prerequisites and configure detected clients idempotently.
|
||||
@@ -154,19 +196,40 @@ export const runSetup = async (
|
||||
if (unsupported !== undefined) return fail(unsupported);
|
||||
let hopperPath = await host.hopperPath();
|
||||
let providerEnvironment = await initialProviderEnvironment(host, hopperPath);
|
||||
const discovery = await discoverSetupActions(
|
||||
const discovery = await discoverSetupActions({
|
||||
host,
|
||||
providerEnvironment,
|
||||
options.installHopper,
|
||||
);
|
||||
const { installHopper, installSkill } = discovery;
|
||||
let { detectedClients } = discovery;
|
||||
forceHopperInstall: options.installHopper,
|
||||
proposeHopper: options.proposeHopper ?? true,
|
||||
selectedClientIds: options.clientIds,
|
||||
installSkillSelection: options.installSkill,
|
||||
});
|
||||
if (discovery.blocker !== undefined) return fail(discovery.blocker);
|
||||
let { installHopper, installSkill } = discovery;
|
||||
let detectedClients: readonly SetupClient[] = discovery.detectedClients;
|
||||
plannedActions = discovery.plannedActions;
|
||||
let approved = options.approved || plannedActions.length === 0;
|
||||
let interactiveApproval = false;
|
||||
if (!approved && confirm !== undefined && !options.structured) {
|
||||
interactiveApproval = await confirm(plannedActions);
|
||||
approved = interactiveApproval;
|
||||
const decision = await confirm(plannedActions);
|
||||
if (typeof decision === "boolean") {
|
||||
interactiveApproval = decision;
|
||||
approved = decision;
|
||||
} else {
|
||||
const selected = new Set(decision.selectedActionIds);
|
||||
plannedActions = plannedActions.filter(({ id }) => selected.has(id));
|
||||
installHopper = plannedActions.some(
|
||||
({ kind }) => kind === "install_hopper",
|
||||
);
|
||||
installSkill = plannedActions.some(
|
||||
({ kind }) => kind === "install_skill",
|
||||
);
|
||||
detectedClients = detectedClients.filter((client) =>
|
||||
selected.has(`configure_client:${client.name}`),
|
||||
);
|
||||
interactiveApproval = decision.approved;
|
||||
approved = decision.approved || plannedActions.length === 0;
|
||||
}
|
||||
}
|
||||
if (!approved)
|
||||
return {
|
||||
@@ -180,8 +243,21 @@ export const runSetup = async (
|
||||
};
|
||||
|
||||
if (installHopper && (interactiveApproval || options.installHopper)) {
|
||||
emitProgress(
|
||||
options,
|
||||
"install_hopper",
|
||||
"Hopper deep-analysis provider",
|
||||
"started",
|
||||
);
|
||||
const installed = await host.installHopper(options.installHopper);
|
||||
if (installed.status === "failed")
|
||||
if (installed.status === "failed") {
|
||||
emitProgress(
|
||||
options,
|
||||
"install_hopper",
|
||||
"Hopper deep-analysis provider",
|
||||
"failed",
|
||||
installed.remediation,
|
||||
);
|
||||
return {
|
||||
status: "needs_human",
|
||||
plannedActions,
|
||||
@@ -191,12 +267,20 @@ export const runSetup = async (
|
||||
code: installed.code,
|
||||
remediation: installed.remediation,
|
||||
};
|
||||
}
|
||||
hopperPath = installed.launcherPath;
|
||||
providerEnvironment = {
|
||||
...providerEnvironment,
|
||||
HOPPER_LAUNCHER_PATH: installed.launcherPath,
|
||||
};
|
||||
appliedActions.push("installed_hopper");
|
||||
emitProgress(
|
||||
options,
|
||||
"install_hopper",
|
||||
"Hopper deep-analysis provider",
|
||||
"completed",
|
||||
installed.launcherPath,
|
||||
);
|
||||
detectedClients = await filterClientsNeedingConfigure(
|
||||
host,
|
||||
detectedClients,
|
||||
@@ -211,15 +295,38 @@ export const runSetup = async (
|
||||
command: registrationCommand(),
|
||||
clients,
|
||||
appliedActions,
|
||||
...(options.onProgress === undefined
|
||||
? {}
|
||||
: { onProgress: options.onProgress }),
|
||||
});
|
||||
if (clientFailure !== undefined) return fail(clientFailure);
|
||||
if (installSkill) {
|
||||
emitProgress(
|
||||
options,
|
||||
"install_skill",
|
||||
"REA reverse-engineering skill",
|
||||
"started",
|
||||
);
|
||||
const skill = await host.installSkill();
|
||||
if (skill === "failed")
|
||||
if (skill === "failed") {
|
||||
emitProgress(
|
||||
options,
|
||||
"install_skill",
|
||||
"REA reverse-engineering skill",
|
||||
"failed",
|
||||
);
|
||||
return fail(
|
||||
"REA analysis skill could not be installed or verified. Check permissions for `~/.agents/skills`, then rerun setup.",
|
||||
);
|
||||
}
|
||||
if (skill === "installed") appliedActions.push("installed_skill");
|
||||
emitProgress(
|
||||
options,
|
||||
"install_skill",
|
||||
"REA reverse-engineering skill",
|
||||
skill === "installed" ? "completed" : "warning",
|
||||
skill === "unchanged" ? "Already current" : undefined,
|
||||
);
|
||||
}
|
||||
const doctor = await host.doctor();
|
||||
const remediation = finalSetupRemediation(
|
||||
@@ -238,11 +345,15 @@ export const runSetup = async (
|
||||
};
|
||||
};
|
||||
|
||||
const discoverSetupActions = async (
|
||||
host: SetupHost,
|
||||
providerEnvironment: SetupProviderEnvironment,
|
||||
forceHopperInstall: boolean,
|
||||
) => {
|
||||
const discoverSetupActions = async (input: {
|
||||
readonly host: SetupHost;
|
||||
readonly providerEnvironment: SetupProviderEnvironment;
|
||||
readonly forceHopperInstall: boolean;
|
||||
readonly proposeHopper: boolean;
|
||||
readonly selectedClientIds: readonly string[] | undefined;
|
||||
readonly installSkillSelection: boolean | undefined;
|
||||
}) => {
|
||||
const { host, providerEnvironment } = input;
|
||||
const initialDoctor = await host.doctor();
|
||||
const linuxHopperRepairNeeded = initialDoctor.checks.some(
|
||||
({ name, ok, detail }) =>
|
||||
@@ -251,13 +362,24 @@ const discoverSetupActions = async (
|
||||
(name === "hopper-version" && detail === "/opt/hopper/bin/Hopper")),
|
||||
);
|
||||
const installHopper =
|
||||
forceHopperInstall ||
|
||||
Object.keys(providerEnvironment).length === 0 ||
|
||||
linuxHopperRepairNeeded;
|
||||
const [detectedClients, installSkill] = await Promise.all([
|
||||
input.forceHopperInstall ||
|
||||
(input.proposeHopper &&
|
||||
(Object.keys(providerEnvironment).length === 0 ||
|
||||
linuxHopperRepairNeeded));
|
||||
const [allDetectedClients, skillNeedsInstall] = await Promise.all([
|
||||
host.detectedClients(),
|
||||
host.skillNeedsInstall(),
|
||||
]);
|
||||
const selectedClientIdSet =
|
||||
input.selectedClientIds === undefined
|
||||
? undefined
|
||||
: new Set(input.selectedClientIds);
|
||||
const detectedClients = allDetectedClients.filter(
|
||||
({ name }) =>
|
||||
selectedClientIdSet === undefined || selectedClientIdSet.has(name),
|
||||
);
|
||||
const installSkill =
|
||||
input.installSkillSelection === false ? false : skillNeedsInstall;
|
||||
const command = registrationCommand();
|
||||
const clients = installHopper
|
||||
? detectedClients
|
||||
@@ -267,21 +389,91 @@ const discoverSetupActions = async (
|
||||
providerEnvironment,
|
||||
command,
|
||||
);
|
||||
const plannedActions = setupPlan(
|
||||
host.platform,
|
||||
installHopper,
|
||||
installSkill,
|
||||
const inspections = await inspectClients(
|
||||
host,
|
||||
clients,
|
||||
providerEnvironment,
|
||||
command,
|
||||
);
|
||||
const invalid = inspections.find(
|
||||
({ inspection }) => inspection.status === "invalid",
|
||||
);
|
||||
const blocker =
|
||||
invalid?.inspection.status === "invalid"
|
||||
? `${invalid.client.displayName ?? invalid.client.name}: ${invalid.inspection.remediation}`
|
||||
: undefined;
|
||||
const clientPlans = inspections.flatMap(({ client, inspection }) =>
|
||||
inspection.status === "create" ||
|
||||
inspection.status === "update" ||
|
||||
(installHopper && inspection.status === "already_current")
|
||||
? [
|
||||
{
|
||||
client,
|
||||
operation:
|
||||
inspection.status === "already_current"
|
||||
? ("update" as const)
|
||||
: inspection.status,
|
||||
...(inspection.status !== "already_current" &&
|
||||
inspection.backupPath !== undefined
|
||||
? { backupPath: inspection.backupPath }
|
||||
: {}),
|
||||
},
|
||||
]
|
||||
: [],
|
||||
);
|
||||
const linuxDistribution =
|
||||
host.platform === "linux" ? await host.linuxDistribution() : undefined;
|
||||
const plannedActions = setupPlan({
|
||||
platform: host.platform,
|
||||
installHopper,
|
||||
installSkill,
|
||||
clients: clientPlans,
|
||||
providerEnvironment,
|
||||
...(linuxDistribution?.packageFamily === undefined
|
||||
? {}
|
||||
: { linuxPackageFamily: linuxDistribution.packageFamily }),
|
||||
});
|
||||
return {
|
||||
installHopper,
|
||||
installSkill,
|
||||
detectedClients: clients,
|
||||
detectedClients: clientPlans.map(({ client }) => client),
|
||||
plannedActions,
|
||||
blocker,
|
||||
};
|
||||
};
|
||||
|
||||
const inspectClients = async (
|
||||
host: SetupHost,
|
||||
clients: readonly SetupClient[],
|
||||
providerEnvironment: SetupProviderEnvironment,
|
||||
command: readonly string[],
|
||||
) =>
|
||||
Promise.all(
|
||||
clients.map(async (client) => ({
|
||||
client,
|
||||
inspection:
|
||||
(await host.inspectClientConfiguration?.(
|
||||
client,
|
||||
providerEnvironment,
|
||||
command,
|
||||
)) ?? ({ status: "update" } as const),
|
||||
})),
|
||||
);
|
||||
|
||||
const emitProgress = (
|
||||
options: SetupOptions,
|
||||
actionId: string,
|
||||
label: string,
|
||||
state: SetupProgressEvent["state"],
|
||||
detail?: string,
|
||||
): void =>
|
||||
options.onProgress?.({
|
||||
actionId,
|
||||
label,
|
||||
state,
|
||||
...(detail === undefined ? {} : { detail }),
|
||||
});
|
||||
|
||||
const filterClientsNeedingConfigure = async (
|
||||
host: SetupHost,
|
||||
detectedClients: readonly SetupClient[],
|
||||
@@ -381,6 +573,7 @@ export const systemSetupHost = (
|
||||
clientConfigurationAligned(client, providerEnvironment, command).then(
|
||||
(aligned) => !aligned,
|
||||
),
|
||||
inspectClientConfiguration: inspectClientConfiguration,
|
||||
skillNeedsInstall: () => canonicalSkillNeedsInstall(homedir()),
|
||||
installSkill: () => installCanonicalSkill(homedir()),
|
||||
doctor: () => runDoctor(undefined, doctorHost),
|
||||
@@ -636,6 +829,59 @@ const clientConfigurationAligned = async (
|
||||
}
|
||||
};
|
||||
|
||||
const inspectClientConfiguration = async (
|
||||
client: SetupClient,
|
||||
providerEnvironment: SetupProviderEnvironment,
|
||||
command: readonly string[],
|
||||
): Promise<ClientConfigurationInspection> => {
|
||||
if (client.format === "unsupported") return { status: "already_current" };
|
||||
const transactionPath = await resolveClientConfigTransactionPath(
|
||||
client.configPath,
|
||||
);
|
||||
if (transactionPath === undefined)
|
||||
return {
|
||||
status: "invalid",
|
||||
remediation:
|
||||
"The configuration path is unsafe or unresolved. Check ownership and symbolic links before rerunning setup.",
|
||||
};
|
||||
let original: string;
|
||||
try {
|
||||
original = await readFile(transactionPath, "utf8");
|
||||
} catch (cause: unknown) {
|
||||
if (isMissing(cause)) return { status: "create" };
|
||||
return {
|
||||
status: "invalid",
|
||||
remediation:
|
||||
"The configuration file could not be read. Check its permissions before rerunning setup.",
|
||||
};
|
||||
}
|
||||
const desired = clientConfigurationDesired(providerEnvironment, command);
|
||||
try {
|
||||
const document =
|
||||
client.format === "toml"
|
||||
? objectSchema.parse(parseToml(original))
|
||||
: parseObject(original);
|
||||
const servers = parseOptionalObject(
|
||||
client.format === "toml" ? document.mcp_servers : document.mcpServers,
|
||||
);
|
||||
if (
|
||||
JSON.stringify(servers[PRODUCT_IDENTITY.mcpServerKey]) ===
|
||||
JSON.stringify(desired)
|
||||
)
|
||||
return { status: "already_current" };
|
||||
} catch {
|
||||
return {
|
||||
status: "invalid",
|
||||
remediation:
|
||||
"The existing configuration is malformed. Repair it before setup applies any other changes.",
|
||||
};
|
||||
}
|
||||
return {
|
||||
status: "update",
|
||||
backupPath: `${client.configPath}.rea.backup`,
|
||||
};
|
||||
};
|
||||
|
||||
const normalizeProviderEnvironment = (
|
||||
environment: SetupProviderEnvironment | string,
|
||||
): SetupProviderEnvironment =>
|
||||
|
||||
@@ -3,6 +3,7 @@ import type {
|
||||
SetupClient,
|
||||
SetupHost,
|
||||
SetupProviderEnvironment,
|
||||
SetupProgressEvent,
|
||||
} from "./Setup.js";
|
||||
|
||||
const failedConfigurationMessage = (
|
||||
@@ -25,19 +26,41 @@ export const configureDetectedClients = async (options: {
|
||||
readonly command: readonly string[];
|
||||
readonly clients: Record<string, ClientConfigurationResult>;
|
||||
readonly appliedActions: string[];
|
||||
readonly onProgress?: (event: SetupProgressEvent) => void;
|
||||
}): Promise<string | undefined> => {
|
||||
let failure: string | undefined;
|
||||
for (const client of options.detectedClients) {
|
||||
const actionId = `configure_client:${client.name}`;
|
||||
const label = client.displayName ?? client.name;
|
||||
options.onProgress?.({ actionId, label, state: "started" });
|
||||
const result = await options.host.configureClient(
|
||||
client,
|
||||
options.providerEnvironment,
|
||||
options.command,
|
||||
);
|
||||
options.clients[client.name] = result;
|
||||
if (result.status === "failed")
|
||||
if (result.status === "failed") {
|
||||
failure ??= failedConfigurationMessage(result.reason);
|
||||
else if (result.status === "configured")
|
||||
options.onProgress?.({
|
||||
actionId,
|
||||
label,
|
||||
state: "failed",
|
||||
detail: failedConfigurationMessage(result.reason),
|
||||
});
|
||||
} else if (result.status === "configured") {
|
||||
options.appliedActions.push(`configured_${client.name}`);
|
||||
options.onProgress?.({ actionId, label, state: "completed" });
|
||||
} else {
|
||||
options.onProgress?.({
|
||||
actionId,
|
||||
label,
|
||||
state: "warning",
|
||||
detail:
|
||||
result.status === "unchanged"
|
||||
? "Already current"
|
||||
: "Manual configuration required",
|
||||
});
|
||||
}
|
||||
}
|
||||
return failure;
|
||||
};
|
||||
|
||||
@@ -4,54 +4,107 @@ import type {
|
||||
SetupProviderEnvironment,
|
||||
} from "./Setup.js";
|
||||
import { PRODUCT_IDENTITY } from "../identity.js";
|
||||
import { homedir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import {
|
||||
linuxHopperInstallDisclosure,
|
||||
type LinuxPackageFamily,
|
||||
} from "./LinuxHopper.js";
|
||||
import { macHopperInstallDisclosure } from "./MacHopper.js";
|
||||
|
||||
/** Preflighted client mutation admitted into the setup plan. */
|
||||
export type SetupClientPlan = Readonly<{
|
||||
client: SetupClient;
|
||||
operation: "create" | "update";
|
||||
backupPath?: string;
|
||||
}>;
|
||||
|
||||
/** Build the complete setup mutation plan before approval. */
|
||||
export const setupPlan = (
|
||||
platform: NodeJS.Platform,
|
||||
installHopper: boolean,
|
||||
installSkill: boolean,
|
||||
clients: readonly SetupClient[],
|
||||
providerEnvironment: SetupProviderEnvironment,
|
||||
): readonly SetupAction[] => [
|
||||
...(installHopper
|
||||
export const setupPlan = (input: {
|
||||
readonly platform: NodeJS.Platform;
|
||||
readonly installHopper: boolean;
|
||||
readonly installSkill: boolean;
|
||||
readonly clients: readonly SetupClientPlan[];
|
||||
readonly providerEnvironment: SetupProviderEnvironment;
|
||||
readonly linuxPackageFamily?: LinuxPackageFamily;
|
||||
}): readonly SetupAction[] => [
|
||||
...(input.installHopper
|
||||
? [
|
||||
{
|
||||
id: "install_hopper",
|
||||
kind: "install_hopper" as const,
|
||||
label: "Hopper deep-analysis provider",
|
||||
target:
|
||||
platform === "darwin"
|
||||
? "~/Applications/Hopper Disassembler.app"
|
||||
input.platform === "darwin"
|
||||
? join(homedir(), "Applications/Hopper Disassembler.app")
|
||||
: "system package manager",
|
||||
detail:
|
||||
platform === "linux"
|
||||
input.platform === "linux"
|
||||
? "Download, verify, and install Hopper plus its Xvfb demo-session dependencies. For the supported demo build, REA uses a private display and selects Hopper's offered demo mode for each analysis session."
|
||||
: "Download the official Hopper package, verify it, and install it. Hopper may show its demo or license prompt when first opened.",
|
||||
external: true,
|
||||
operation: "install" as const,
|
||||
...(input.platform === "linux"
|
||||
? input.linuxPackageFamily === undefined
|
||||
? {}
|
||||
: linuxDisclosure(input.linuxPackageFamily)
|
||||
: {
|
||||
networkOrigins: macHopperInstallDisclosure.networkOrigins,
|
||||
commands: macHopperInstallDisclosure.commands,
|
||||
}),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...clients
|
||||
.filter(({ format }) => format !== "unsupported")
|
||||
...input.clients
|
||||
.filter(({ client }) => client.format !== "unsupported")
|
||||
.map(
|
||||
(client): SetupAction => ({
|
||||
({ client, operation, backupPath }): SetupAction => ({
|
||||
id: `configure_client:${client.name}`,
|
||||
kind: "configure_client",
|
||||
label: client.displayName ?? client.name,
|
||||
target: client.configPath,
|
||||
detail: clientConfigurationDetail(client.name, providerEnvironment),
|
||||
detail: clientConfigurationDetail(
|
||||
client.displayName ?? client.name,
|
||||
input.providerEnvironment,
|
||||
),
|
||||
external: false,
|
||||
operation,
|
||||
...(backupPath === undefined ? {} : { backupPath }),
|
||||
}),
|
||||
),
|
||||
...(installSkill
|
||||
...(input.installSkill
|
||||
? [
|
||||
{
|
||||
id: "install_skill",
|
||||
kind: "install_skill" as const,
|
||||
target: `~/.agents/skills/${PRODUCT_IDENTITY.skillName}/SKILL.md`,
|
||||
label: "REA reverse-engineering skill",
|
||||
target: join(
|
||||
homedir(),
|
||||
".agents/skills",
|
||||
PRODUCT_IDENTITY.skillName,
|
||||
"SKILL.md",
|
||||
),
|
||||
detail:
|
||||
"Install or update the bundled REA reverse-engineering skill.",
|
||||
external: false,
|
||||
operation: "install" as const,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
];
|
||||
|
||||
const linuxDisclosure = (family: LinuxPackageFamily) => {
|
||||
const disclosure = linuxHopperInstallDisclosure(
|
||||
family,
|
||||
process.getuid?.() === 0,
|
||||
);
|
||||
return {
|
||||
networkOrigins: [disclosure.downloadUrl],
|
||||
commands: disclosure.commands,
|
||||
integrity: `${String(disclosure.expectedBytes)} bytes · SHA-1 ${disclosure.expectedSha1}`,
|
||||
};
|
||||
};
|
||||
|
||||
const clientConfigurationDetail = (
|
||||
client: string,
|
||||
environment: SetupProviderEnvironment,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { join } from "node:path";
|
||||
/** One supported client configuration location. */
|
||||
export interface SetupClient {
|
||||
readonly name: string;
|
||||
readonly displayName?: string;
|
||||
readonly configPath: string;
|
||||
readonly markerPath?: string;
|
||||
readonly format?: "json" | "toml" | "unsupported";
|
||||
@@ -70,6 +71,7 @@ export const SUPPORTED_CLIENT_DEFINITIONS = [
|
||||
export const supportedClients = (home: string): readonly SetupClient[] =>
|
||||
SUPPORTED_CLIENT_DEFINITIONS.map((definition) => ({
|
||||
name: definition.name,
|
||||
displayName: definition.displayName,
|
||||
configPath: join(home, ...definition.configPath),
|
||||
markerPath: join(home, ...definition.markerPath),
|
||||
format: definition.format,
|
||||
|
||||
+89
-38
@@ -1,6 +1,5 @@
|
||||
import { Cli, z } from "incur";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { createInterface } from "node:readline/promises";
|
||||
|
||||
import { runDoctor } from "./application/Doctor.js";
|
||||
import {
|
||||
@@ -13,11 +12,7 @@ import { projectManagedApplicationGraphEvidence } from "./application/ManagedApp
|
||||
import { verifyManagedNativeBoundariesEvidence } from "./application/ManagedNativeVerificationService.js";
|
||||
import { importManagedReconstructionEvidence } from "./application/ManagedReconstructionService.js";
|
||||
import { planManagedRuntimeCorrelationEvidence } from "./application/ManagedRuntimeCorrelationService.js";
|
||||
import {
|
||||
runSetup,
|
||||
systemSetupHost,
|
||||
type SetupAction,
|
||||
} from "./application/Setup.js";
|
||||
import { runSetup, systemSetupHost } from "./application/Setup.js";
|
||||
import { runUninstall } from "./application/Uninstall.js";
|
||||
import { runUpgrade, systemUpgradeHost } from "./application/Upgrade.js";
|
||||
import { PRODUCT_IDENTITY } from "./identity.js";
|
||||
@@ -47,6 +42,12 @@ import {
|
||||
type AnalysisProviderSelector,
|
||||
} from "./contracts/providerSelection.js";
|
||||
import { createSystemDoctorHost } from "./doctorRuntime.js";
|
||||
import {
|
||||
conciseSetupResult,
|
||||
confirmInteractiveSetup,
|
||||
renderInteractiveSetupResult,
|
||||
renderSetupProgress,
|
||||
} from "./cliSetup.js";
|
||||
|
||||
/**
|
||||
* Build the one-shot Incur CLI without starting Hopper at import time.
|
||||
@@ -188,6 +189,7 @@ const registerSetupCommands = (
|
||||
): void => {
|
||||
cli.command(CLI_COMMANDS.setup, {
|
||||
description: "Install requirements and configure agents",
|
||||
outputPolicy: "agent-only",
|
||||
options: z.object({
|
||||
yes: z
|
||||
.boolean()
|
||||
@@ -197,21 +199,42 @@ const registerSetupCommands = (
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Also approve Hopper installation with --yes"),
|
||||
client: z
|
||||
.array(
|
||||
z.enum([
|
||||
"claude_code",
|
||||
"claude_desktop",
|
||||
"codex",
|
||||
"cursor",
|
||||
"gemini_cli",
|
||||
"windsurf",
|
||||
]),
|
||||
)
|
||||
.default([])
|
||||
.describe("Agent integration to configure; repeat for multiple agents"),
|
||||
allDetected: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Configure every detected supported agent"),
|
||||
skill: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe("Install or skip the bundled REA skill"),
|
||||
dryRun: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Print the resolved plan without applying it"),
|
||||
accessible: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Use sequential accessible setup prompts"),
|
||||
}),
|
||||
alias: { yes: "y", installHopper: "install-hopper" },
|
||||
run: ({ options, formatExplicit }) =>
|
||||
alias: {
|
||||
yes: "y",
|
||||
},
|
||||
run: ({ options, formatExplicit, agent }) =>
|
||||
logCliCommand(logger, "setup", () =>
|
||||
runSetup(
|
||||
{
|
||||
approved: options.yes,
|
||||
installHopper: options.installHopper,
|
||||
structured: formatExplicit,
|
||||
},
|
||||
systemSetupHost(createSystemDoctorHost()),
|
||||
options.yes || formatExplicit || process.stdin.isTTY !== true
|
||||
? undefined
|
||||
: confirmSetup,
|
||||
),
|
||||
runSetupCommand({ options, formatExplicit, agent }),
|
||||
),
|
||||
});
|
||||
cli.command(CLI_COMMANDS.doctor, {
|
||||
@@ -249,26 +272,54 @@ const registerSetupCommands = (
|
||||
});
|
||||
};
|
||||
|
||||
const confirmSetup = async (
|
||||
actions: readonly SetupAction[],
|
||||
): Promise<boolean> => {
|
||||
process.stdout.write("\nREA setup plan\n");
|
||||
for (const action of actions)
|
||||
process.stdout.write(
|
||||
` - ${action.detail}\n ${action.target}${action.external ? " (external software)" : ""}\n`,
|
||||
const runSetupCommand = async (input: {
|
||||
readonly options: {
|
||||
readonly yes: boolean;
|
||||
readonly installHopper: boolean;
|
||||
readonly client: readonly string[];
|
||||
readonly allDetected: boolean;
|
||||
readonly skill?: boolean | undefined;
|
||||
readonly dryRun: boolean;
|
||||
readonly accessible: boolean;
|
||||
};
|
||||
readonly formatExplicit: boolean;
|
||||
readonly agent: boolean;
|
||||
}) => {
|
||||
const { options } = input;
|
||||
const interactive =
|
||||
!options.yes &&
|
||||
!options.dryRun &&
|
||||
!input.formatExplicit &&
|
||||
process.stdin.isTTY === true &&
|
||||
process.stderr.isTTY === true;
|
||||
const hasExplicitScope =
|
||||
options.allDetected ||
|
||||
options.client.length > 0 ||
|
||||
options.skill !== undefined ||
|
||||
options.installHopper;
|
||||
if (options.yes && !hasExplicitScope)
|
||||
process.stderr.write(
|
||||
"! Implicit `rea setup --yes` scope is deprecated; use `--all-detected --skill` to retain it.\n",
|
||||
);
|
||||
const prompt = createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
});
|
||||
try {
|
||||
const answer = (await prompt.question("Continue? [Y/n] "))
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
return answer === "" || answer === "y" || answer === "yes";
|
||||
} finally {
|
||||
prompt.close();
|
||||
}
|
||||
const result = await runSetup(
|
||||
{
|
||||
approved: options.yes && !options.dryRun,
|
||||
installHopper: options.installHopper,
|
||||
structured: input.formatExplicit || options.dryRun,
|
||||
proposeHopper: !hasExplicitScope || options.installHopper,
|
||||
...(!hasExplicitScope || options.allDetected
|
||||
? {}
|
||||
: { clientIds: options.client }),
|
||||
...(!hasExplicitScope ? {} : { installSkill: options.skill ?? false }),
|
||||
...(interactive ? { onProgress: renderSetupProgress } : {}),
|
||||
},
|
||||
systemSetupHost(createSystemDoctorHost()),
|
||||
interactive
|
||||
? (actions) => confirmInteractiveSetup(actions, options.accessible)
|
||||
: undefined,
|
||||
);
|
||||
if (interactive) renderInteractiveSetupResult(result);
|
||||
return input.formatExplicit ? result : conciseSetupResult(result);
|
||||
};
|
||||
|
||||
const registerXrefsCommand = (
|
||||
|
||||
+360
@@ -0,0 +1,360 @@
|
||||
import {
|
||||
cancel,
|
||||
confirm,
|
||||
intro,
|
||||
isCancel,
|
||||
multiselect,
|
||||
outro,
|
||||
select,
|
||||
} from "@clack/prompts";
|
||||
|
||||
import type {
|
||||
SetupAction,
|
||||
SetupConfirmationDecision,
|
||||
SetupProgressEvent,
|
||||
SetupResult,
|
||||
} from "./application/Setup.js";
|
||||
import { SUPPORTED_CLIENT_DEFINITIONS } from "./application/SupportedClients.js";
|
||||
|
||||
const clientDisplayNames: ReadonlyMap<string, string> = new Map(
|
||||
SUPPORTED_CLIENT_DEFINITIONS.map(({ name, displayName }) => [
|
||||
name,
|
||||
displayName,
|
||||
]),
|
||||
);
|
||||
|
||||
const promptStreams = {
|
||||
input: process.stdin,
|
||||
output: process.stderr,
|
||||
withGuide: true,
|
||||
} as const;
|
||||
|
||||
type SetupMode = "recommended" | "custom" | "skip";
|
||||
|
||||
/** Run the inline setup picker, exact preflight, and default-No consent. */
|
||||
export const confirmInteractiveSetup = async (
|
||||
actions: readonly SetupAction[],
|
||||
accessible: boolean,
|
||||
): Promise<SetupConfirmationDecision> => {
|
||||
intro("REA setup", promptStreams);
|
||||
renderValueIntroduction();
|
||||
renderDetectedSummary(actions);
|
||||
renderKeyboardHelp(accessible);
|
||||
const mode = await selectSetupMode(actions, accessible);
|
||||
if (mode === undefined) return cancelledDecision(actions);
|
||||
if (mode === "skip") {
|
||||
cancel("No changes were made.", promptStreams);
|
||||
return {
|
||||
approved: false,
|
||||
selectedActionIds: actions.map(({ id }) => id),
|
||||
};
|
||||
}
|
||||
const selectedActionIds =
|
||||
mode === "recommended"
|
||||
? actions.map(({ id }) => id)
|
||||
: accessible
|
||||
? await selectActionsAccessibly(actions)
|
||||
: await selectActions(actions);
|
||||
if (selectedActionIds === undefined) return cancelledDecision(actions);
|
||||
if (selectedActionIds.length === 0) {
|
||||
cancel("Nothing selected. No changes were made.", promptStreams);
|
||||
return { approved: false, selectedActionIds };
|
||||
}
|
||||
const selected = new Set(selectedActionIds);
|
||||
const selectedActions = actions.filter(({ id }) => selected.has(id));
|
||||
renderPreflight(selectedActions);
|
||||
const approved = await confirm({
|
||||
...promptStreams,
|
||||
message:
|
||||
selectedActions.length === 1
|
||||
? "Apply this change?"
|
||||
: `Apply these ${String(selectedActions.length)} changes?`,
|
||||
initialValue: false,
|
||||
active: "Yes, apply",
|
||||
inactive: "No, cancel",
|
||||
});
|
||||
if (isCancel(approved) || !approved) {
|
||||
cancel("Setup cancelled. No changes were made.", promptStreams);
|
||||
return { approved: false, selectedActionIds };
|
||||
}
|
||||
return { approved: true, selectedActionIds };
|
||||
};
|
||||
|
||||
/** Render stable, append-only progress for real setup operations. */
|
||||
export const renderSetupProgress = (event: SetupProgressEvent): void => {
|
||||
const symbol =
|
||||
event.state === "started"
|
||||
? "◇"
|
||||
: event.state === "completed"
|
||||
? "◆"
|
||||
: event.state === "warning"
|
||||
? "!"
|
||||
: "✗";
|
||||
const suffix = event.detail === undefined ? "" : ` · ${event.detail}`;
|
||||
writeLine(`${symbol} ${event.label}${suffix}`);
|
||||
};
|
||||
|
||||
/** Finish an interactive setup journey without exposing the full doctor catalog. */
|
||||
export const renderInteractiveSetupResult = (result: SetupResult): void => {
|
||||
if (result.status === "ready") {
|
||||
const changedClients = Object.entries(result.clients)
|
||||
.filter(([, client]) => client.status === "configured")
|
||||
.map(([client]) => clientDisplayNames.get(client) ?? client);
|
||||
const readyClients = readyAgentClients(result, changedClients);
|
||||
renderReadyCapabilities(result, readyClients);
|
||||
outro(
|
||||
changedClients.length === 0
|
||||
? "REA is ready for local app analysis."
|
||||
: `Restart ${changedClients.join(", ")} to load REA.`,
|
||||
promptStreams,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (result.status === "planned") return;
|
||||
writeLine(`! ${result.remediation ?? "Setup needs attention."}`);
|
||||
outro("Run `rea doctor` for the remaining checks.", promptStreams);
|
||||
};
|
||||
|
||||
/** Keep default non-TTY output actionable without emitting the full catalog. */
|
||||
export const conciseSetupResult = (result: SetupResult) => ({
|
||||
status: result.status,
|
||||
plannedActions: result.plannedActions,
|
||||
appliedActions: result.appliedActions,
|
||||
clients: result.clients,
|
||||
doctor: {
|
||||
healthy: result.doctor.healthy,
|
||||
checks: result.doctor.checks.filter(({ ok }) => !ok),
|
||||
},
|
||||
...(result.code === undefined ? {} : { code: result.code }),
|
||||
...(result.remediation === undefined
|
||||
? {}
|
||||
: { remediation: result.remediation }),
|
||||
});
|
||||
|
||||
const selectActions = async (
|
||||
actions: readonly SetupAction[],
|
||||
): Promise<readonly string[] | undefined> => {
|
||||
const selection = await multiselect({
|
||||
...promptStreams,
|
||||
message: "Choose what REA should configure",
|
||||
options: actions.map((action) => ({
|
||||
value: action.id,
|
||||
label: `${action.label} (${actionModality(action)})`,
|
||||
hint: `${action.operation} · ${action.target}`,
|
||||
})),
|
||||
initialValues: actions.map(({ id }) => id),
|
||||
required: false,
|
||||
maxItems: Math.max(
|
||||
3,
|
||||
Math.min(actions.length, (process.stderr.rows ?? 24) - 8),
|
||||
),
|
||||
showInstructions: true,
|
||||
});
|
||||
return isCancel(selection) ? undefined : selection;
|
||||
};
|
||||
|
||||
const selectActionsAccessibly = async (
|
||||
actions: readonly SetupAction[],
|
||||
): Promise<readonly string[] | undefined> => {
|
||||
const selected: string[] = [];
|
||||
for (const action of actions) {
|
||||
const included = await confirm({
|
||||
...promptStreams,
|
||||
message: `Include ${action.label} (${actionModality(action)})? ${action.target}`,
|
||||
initialValue: true,
|
||||
vertical: true,
|
||||
});
|
||||
if (isCancel(included)) return undefined;
|
||||
if (included) selected.push(action.id);
|
||||
}
|
||||
return selected;
|
||||
};
|
||||
|
||||
const selectSetupMode = async (
|
||||
actions: readonly SetupAction[],
|
||||
accessible: boolean,
|
||||
): Promise<SetupMode | undefined> => {
|
||||
if (accessible) return selectSetupModeAccessibly();
|
||||
const mode = await select<SetupMode>({
|
||||
...promptStreams,
|
||||
message: "Choose a setup",
|
||||
options: [
|
||||
{
|
||||
value: "recommended",
|
||||
label: "Set up all available capabilities",
|
||||
hint: `recommended · ${actionCount(actions.length)}`,
|
||||
},
|
||||
{
|
||||
value: "custom",
|
||||
label: "Customize setup",
|
||||
hint: "choose integrations and components",
|
||||
},
|
||||
{
|
||||
value: "skip",
|
||||
label: "No thanks",
|
||||
hint: "make no changes",
|
||||
},
|
||||
],
|
||||
initialValue: "recommended",
|
||||
});
|
||||
return isCancel(mode) ? undefined : mode;
|
||||
};
|
||||
|
||||
const selectSetupModeAccessibly = async (): Promise<SetupMode | undefined> => {
|
||||
const recommended = await confirm({
|
||||
...promptStreams,
|
||||
message: "Use the recommended complete setup?",
|
||||
initialValue: true,
|
||||
vertical: true,
|
||||
});
|
||||
if (isCancel(recommended)) return undefined;
|
||||
if (recommended) return "recommended";
|
||||
const customize = await confirm({
|
||||
...promptStreams,
|
||||
message: "Customize integrations and components?",
|
||||
initialValue: true,
|
||||
vertical: true,
|
||||
});
|
||||
if (isCancel(customize)) return undefined;
|
||||
return customize ? "custom" : "skip";
|
||||
};
|
||||
|
||||
const renderValueIntroduction = (): void => {
|
||||
writeLine("│ Understand local apps and binaries from your coding agent.");
|
||||
writeLine("│");
|
||||
writeLine("│ • Trace how a feature works with local evidence.");
|
||||
writeLine(
|
||||
"│ • Use the same analysis capabilities from REA's CLI and supported agents.",
|
||||
);
|
||||
writeLine(
|
||||
"│ • Keep analyzed targets on this machine instead of uploading them to a hosted service.",
|
||||
);
|
||||
};
|
||||
|
||||
const renderDetectedSummary = (actions: readonly SetupAction[]): void => {
|
||||
const clients = actions.filter(({ kind }) => kind === "configure_client");
|
||||
writeLine("│");
|
||||
if (clients.length === 0) {
|
||||
writeLine("◆ No agent integrations need configuration");
|
||||
} else {
|
||||
writeLine(`◆ Detected ${humanList(clients.map(({ label }) => label))}`);
|
||||
for (const client of clients) {
|
||||
writeLine(
|
||||
`│ ${client.label} · ${actionModality(client)} · ${client.operation}`,
|
||||
);
|
||||
writeLine(`│ ${client.target}`);
|
||||
}
|
||||
}
|
||||
const components = actions.filter(({ kind }) => kind !== "configure_client");
|
||||
if (components.length > 0) {
|
||||
writeLine("│");
|
||||
writeLine(
|
||||
`│ Also available: ${components.map((action) => `${action.label} (${actionModality(action)})`).join(", ")}`,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const renderKeyboardHelp = (accessible: boolean): void => {
|
||||
writeLine("│");
|
||||
writeLine(
|
||||
accessible
|
||||
? "│ Keys: Enter answer · Ctrl-C cancel"
|
||||
: "│ Keys: ↑/↓ navigate · Space toggle · Enter confirm · Ctrl-C cancel",
|
||||
);
|
||||
};
|
||||
|
||||
const renderReadyCapabilities = (
|
||||
result: SetupResult,
|
||||
readyClients: readonly string[],
|
||||
): void => {
|
||||
writeLine("◆ What you can do now");
|
||||
const providers = readyProviders(result);
|
||||
if (providers.length > 0)
|
||||
writeLine(`│ Deep analysis: ${humanList(providers)}`);
|
||||
if (readyClients.length > 0)
|
||||
writeLine(`│ Agent access: ${humanList(readyClients)}`);
|
||||
if (result.doctor.identity?.skill.state === "aligned")
|
||||
writeLine("│ Guided reverse-engineering workflows: installed");
|
||||
if (providers.length > 0) writeLine("│ CLI: rea analyze /path/to/app");
|
||||
const firstClient = readyClients[0];
|
||||
if (firstClient !== undefined)
|
||||
writeLine(
|
||||
`│ Try in ${firstClient}: "Use REA to explain how a feature works in /path/to/app."`,
|
||||
);
|
||||
};
|
||||
|
||||
const readyAgentClients = (
|
||||
result: SetupResult,
|
||||
changedClients: readonly string[],
|
||||
): readonly string[] => {
|
||||
const alignedClients = (result.doctor.identity?.registrations ?? [])
|
||||
.filter(({ state }) => state === "aligned")
|
||||
.map(({ client }) => clientDisplayNames.get(client) ?? client);
|
||||
return [...new Set([...alignedClients, ...changedClients])];
|
||||
};
|
||||
|
||||
const readyProviders = (result: SetupResult): readonly string[] => {
|
||||
const providers = [
|
||||
...(result.doctor.hopperPath === undefined ? [] : ["Hopper"]),
|
||||
...(result.doctor.providerInspections ?? [])
|
||||
.filter(({ available }) => available)
|
||||
.map(({ id }) => displayProviderId(id)),
|
||||
];
|
||||
return [...new Set(providers)];
|
||||
};
|
||||
|
||||
const displayProviderId = (id: string): string =>
|
||||
id.length === 0 ? id : `${id[0]?.toUpperCase() ?? ""}${id.slice(1)}`;
|
||||
|
||||
const actionModality = (action: SetupAction): string => {
|
||||
if (action.kind === "configure_client") return "MCP";
|
||||
if (action.kind === "install_hopper") return "provider";
|
||||
return "skill";
|
||||
};
|
||||
|
||||
const actionCount = (count: number): string =>
|
||||
`${String(count)} ${count === 1 ? "change" : "changes"}`;
|
||||
|
||||
const humanList = (values: readonly string[]): string => {
|
||||
if (values.length < 2) return values[0] ?? "";
|
||||
if (values.length === 2) return `${values[0]} and ${values[1]}`;
|
||||
return `${values.slice(0, -1).join(", ")}, and ${values.at(-1)}`;
|
||||
};
|
||||
|
||||
const renderPreflight = (actions: readonly SetupAction[]): void => {
|
||||
writeLine("│");
|
||||
writeLine("◆ Ready to review");
|
||||
for (const action of actions) {
|
||||
writeLine("│");
|
||||
writeLine(`│ ${action.operation.toUpperCase()} ${action.label}`);
|
||||
writeLine(`│ ${action.target}`);
|
||||
if (action.backupPath !== undefined)
|
||||
writeLine(`│ backup: ${action.backupPath}`);
|
||||
for (const origin of action.networkOrigins ?? [])
|
||||
writeLine(`│ network: ${origin}`);
|
||||
if (action.integrity !== undefined)
|
||||
writeLine(`│ integrity: ${action.integrity}`);
|
||||
for (const command of action.commands ?? [])
|
||||
writeLine(`│ command: ${command}`);
|
||||
writeLine(`│ ${action.detail}`);
|
||||
if (action.external) writeLine("│ external software");
|
||||
}
|
||||
writeLine("│");
|
||||
writeLine(
|
||||
"│ REA will preserve unrelated configuration and will not install or upgrade Node.js, npm, Homebrew, Java, or Ghidra.",
|
||||
);
|
||||
};
|
||||
|
||||
const cancelledDecision = (
|
||||
actions: readonly SetupAction[],
|
||||
): SetupConfirmationDecision => {
|
||||
cancel("Setup cancelled. No changes were made.", promptStreams);
|
||||
return {
|
||||
approved: false,
|
||||
selectedActionIds: actions.map(({ id }) => id),
|
||||
};
|
||||
};
|
||||
|
||||
const writeLine = (line: string): void => {
|
||||
process.stderr.write(`${line}\n`);
|
||||
};
|
||||
Reference in New Issue
Block a user