feat(setup): make installation explicit and safe

This commit is contained in:
morluto
2026-07-13 15:13:59 +08:00
parent 1d1fe7b212
commit 3793889ce8
12 changed files with 793 additions and 497 deletions
+44 -5
View File
@@ -1,5 +1,6 @@
import { Cli, z } from "incur";
import { fileURLToPath } from "node:url";
import { createInterface } from "node:readline/promises";
import { runDoctor } from "./application/Doctor.js";
import {
@@ -7,7 +8,7 @@ import {
runProviderAnalysis,
runSessionStatus,
} from "./application/DirectAnalysis.js";
import { runSetup } from "./application/Setup.js";
import { runSetup, type SetupAction } from "./application/Setup.js";
import { runUninstall } from "./application/Uninstall.js";
import { runUpgrade, systemUpgradeHost } from "./application/Upgrade.js";
import { PRODUCT_IDENTITY } from "./identity.js";
@@ -76,11 +77,27 @@ const registerCoreCommands = (
yes: z
.boolean()
.default(false)
.describe("Approve prerequisite installation"),
.describe("Approve user-owned setup actions without prompting"),
installHopper: z
.boolean()
.default(false)
.describe("Also approve Hopper installation with --yes"),
}),
alias: { yes: "y" },
run: ({ options }) =>
logCliCommand(logger, "setup", () => runSetup(options.yes)),
alias: { yes: "y", installHopper: "install-hopper" },
run: ({ options, formatExplicit }) =>
logCliCommand(logger, "setup", () =>
runSetup(
{
approved: options.yes,
installHopper: options.installHopper,
structured: formatExplicit,
},
undefined,
options.yes || formatExplicit || process.stdin.isTTY !== true
? undefined
: confirmSetup,
),
),
});
cli.command("doctor", {
description: "Check whether REA is ready",
@@ -163,6 +180,28 @@ const registerCoreCommands = (
});
};
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 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 registerXrefsCommand = (
cli: ReturnType<typeof Cli.create>,
logger: Logger,