2026-07-18 04:11:29 +00:00
|
|
|
import { access } from "node:fs/promises";
|
2026-07-12 06:34:27 +08:00
|
|
|
import { homedir } from "node:os";
|
2026-07-18 04:11:29 +00:00
|
|
|
import { resolve } from "node:path";
|
2026-07-12 06:34:27 +08:00
|
|
|
|
|
|
|
|
import { PRODUCT_IDENTITY } from "../identity.js";
|
2026-07-13 15:13:45 +08:00
|
|
|
import { supportsNodeVersion } from "../domain/runtimeVersion.js";
|
2026-07-16 00:02:49 +08:00
|
|
|
import {
|
|
|
|
|
runDoctor,
|
|
|
|
|
systemDoctorHost,
|
|
|
|
|
type DoctorHost,
|
2026-10-05 23:06:19 +08:00
|
|
|
type DoctorReport,
|
2026-07-22 20:38:26 +08:00
|
|
|
type DoctorScope,
|
2026-07-16 00:02:49 +08:00
|
|
|
} from "./Doctor.js";
|
2026-07-12 23:42:20 +00:00
|
|
|
import {
|
|
|
|
|
installLinuxHopper,
|
|
|
|
|
readLinuxDistribution,
|
|
|
|
|
type LinuxDistribution,
|
|
|
|
|
} from "./LinuxHopper.js";
|
2026-07-13 15:13:45 +08:00
|
|
|
import { installMacHopper } from "./MacHopper.js";
|
2026-07-13 19:09:27 +00:00
|
|
|
import { configureDetectedClients } from "./SetupClients.js";
|
2026-07-14 01:12:05 +00:00
|
|
|
import { supportedClients, type SetupClient } from "./SupportedClients.js";
|
|
|
|
|
export type { SetupClient } from "./SupportedClients.js";
|
2026-07-14 20:14:58 +00:00
|
|
|
import {
|
|
|
|
|
canonicalSkillNeedsInstall,
|
|
|
|
|
installCanonicalSkill,
|
|
|
|
|
} from "./SetupSkill.js";
|
2026-10-05 23:06:19 +08:00
|
|
|
import { discoverSetupState, planSetupActions } from "./SetupPlan.js";
|
2026-07-18 04:11:29 +00:00
|
|
|
import {
|
|
|
|
|
clientConfigurationAligned,
|
2026-10-05 23:06:19 +08:00
|
|
|
configureClientConfiguration,
|
2026-07-18 04:11:29 +00:00
|
|
|
configureJsonClient,
|
|
|
|
|
configureTomlClient,
|
2026-07-18 05:18:05 +00:00
|
|
|
inspectClientConfiguration,
|
2026-07-18 04:11:29 +00:00
|
|
|
} from "./SetupClientConfiguration.js";
|
2026-07-18 05:18:05 +00:00
|
|
|
export { configureJsonClient, configureTomlClient };
|
2026-07-13 21:08:33 +00:00
|
|
|
import {
|
|
|
|
|
setupInstallFailure,
|
|
|
|
|
type SetupFailureCode,
|
|
|
|
|
type SetupHopperInstallResult,
|
|
|
|
|
} from "./SetupInstallFailure.js";
|
2026-09-29 07:08:46 +08:00
|
|
|
import { providerRegistrationEnvironment } from "./SetupRegistrationEnvironment.js";
|
2026-07-13 21:22:51 +00:00
|
|
|
export type { SetupHopperInstallResult } from "./SetupInstallFailure.js";
|
2026-07-13 18:20:40 +08:00
|
|
|
|
2026-07-16 00:02:49 +08:00
|
|
|
/** Exact non-secret provider variables propagated into managed registrations. */
|
|
|
|
|
export type SetupProviderEnvironment = Readonly<Record<string, string>>;
|
|
|
|
|
|
2026-07-18 05:18:05 +00:00
|
|
|
export { canonicalSkillNeedsInstall, installCanonicalSkill };
|
2026-07-12 06:34:27 +08:00
|
|
|
|
2026-10-05 23:06:19 +08:00
|
|
|
/** Resolve the executable and arguments used in a managed MCP registration. */
|
|
|
|
|
export const setupRegistrationCommand = (
|
|
|
|
|
platform: NodeJS.Platform,
|
|
|
|
|
useNpmRunner: boolean = process.env.npm_command === "exec",
|
|
|
|
|
): readonly string[] =>
|
|
|
|
|
useNpmRunner
|
2026-07-20 17:11:06 +08:00
|
|
|
? PRODUCT_IDENTITY.mcpCommand.split(" ")
|
2026-10-05 23:06:19 +08:00
|
|
|
: platform === "win32"
|
|
|
|
|
? [
|
|
|
|
|
process.execPath,
|
|
|
|
|
resolve(process.argv[1] ?? PRODUCT_IDENTITY.cliBinary),
|
|
|
|
|
"mcp",
|
|
|
|
|
]
|
|
|
|
|
: [resolve(process.argv[1] ?? PRODUCT_IDENTITY.cliBinary), "mcp"];
|
2026-07-12 23:42:20 +00:00
|
|
|
|
2026-07-12 06:34:27 +08:00
|
|
|
/** Result of one backup/write/readback transaction. */
|
|
|
|
|
export type ClientConfigurationResult =
|
|
|
|
|
| {
|
2026-07-12 23:42:20 +00:00
|
|
|
readonly status: "unchanged" | "configured" | "skipped";
|
2026-07-12 06:34:27 +08:00
|
|
|
readonly backupPath?: string;
|
|
|
|
|
}
|
|
|
|
|
| {
|
|
|
|
|
readonly status: "failed";
|
2026-07-14 20:50:07 +00:00
|
|
|
readonly reason: "path" | "backup" | "write" | "readback";
|
2026-07-12 06:34:27 +08:00
|
|
|
};
|
2026-07-18 11:59:16 +08:00
|
|
|
|
|
|
|
|
/** 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;
|
|
|
|
|
};
|
2026-07-18 05:18:05 +00:00
|
|
|
/** Effects required by the idempotent, non-blocking setup workflow. */
|
2026-07-12 06:34:27 +08:00
|
|
|
export interface SetupHost {
|
|
|
|
|
readonly platform: NodeJS.Platform;
|
|
|
|
|
readonly nodeVersion: string;
|
|
|
|
|
macosVersion(): Promise<string | undefined>;
|
2026-07-12 23:42:20 +00:00
|
|
|
linuxDistribution(): Promise<LinuxDistribution | undefined>;
|
2026-07-12 06:34:27 +08:00
|
|
|
hopperPath(): Promise<string | undefined>;
|
2026-07-15 06:52:52 +00:00
|
|
|
installHopper(replaceExisting: boolean): Promise<SetupHopperInstallResult>;
|
2026-07-16 00:02:49 +08:00
|
|
|
providerEnvironment?(): Promise<SetupProviderEnvironment>;
|
2026-07-12 06:34:27 +08:00
|
|
|
detectedClients(): Promise<readonly SetupClient[]>;
|
2026-10-05 23:06:19 +08:00
|
|
|
supportedClients?(): Promise<readonly SetupClient[]>;
|
2026-07-12 09:12:13 +08:00
|
|
|
configureClient(
|
|
|
|
|
client: SetupClient,
|
2026-07-16 00:02:49 +08:00
|
|
|
providerEnvironment: SetupProviderEnvironment,
|
2026-07-12 23:42:20 +00:00
|
|
|
command: readonly string[],
|
2026-07-12 09:12:13 +08:00
|
|
|
): Promise<ClientConfigurationResult>;
|
2026-07-14 22:00:42 +00:00
|
|
|
clientNeedsConfigure(
|
|
|
|
|
client: SetupClient,
|
2026-07-16 00:02:49 +08:00
|
|
|
providerEnvironment: SetupProviderEnvironment,
|
2026-07-14 22:00:42 +00:00
|
|
|
command: readonly string[],
|
|
|
|
|
): Promise<boolean>;
|
2026-07-18 11:59:16 +08:00
|
|
|
inspectClientConfiguration?(
|
|
|
|
|
client: SetupClient,
|
|
|
|
|
providerEnvironment: SetupProviderEnvironment,
|
|
|
|
|
command: readonly string[],
|
|
|
|
|
): Promise<ClientConfigurationInspection>;
|
2026-07-14 20:14:58 +00:00
|
|
|
skillNeedsInstall(): Promise<boolean>;
|
2026-07-12 06:34:27 +08:00
|
|
|
installSkill(): Promise<"installed" | "unchanged" | "failed">;
|
2026-07-22 20:38:26 +08:00
|
|
|
doctor(scope?: DoctorScope): Promise<Awaited<ReturnType<typeof runDoctor>>>;
|
2026-07-12 06:34:27 +08:00
|
|
|
}
|
2026-07-18 05:18:05 +00:00
|
|
|
/** Structured setup outcome carrying remediation instead of prompting. */
|
2026-07-12 06:34:27 +08:00
|
|
|
export interface SetupResult {
|
2026-10-05 23:06:19 +08:00
|
|
|
readonly status:
|
|
|
|
|
| "planned"
|
|
|
|
|
| "cancelled"
|
|
|
|
|
| "needs_confirmation"
|
|
|
|
|
| "ready"
|
|
|
|
|
| "needs_human";
|
2026-07-13 15:13:45 +08:00
|
|
|
readonly plannedActions: readonly SetupAction[];
|
|
|
|
|
readonly appliedActions: readonly string[];
|
2026-07-12 06:34:27 +08:00
|
|
|
readonly clients: Readonly<Record<string, ClientConfigurationResult>>;
|
2026-10-05 23:06:19 +08:00
|
|
|
readonly doctor: SetupDoctorSummary;
|
|
|
|
|
/** Supported-client discovery state captured before setup mutations. */
|
|
|
|
|
readonly clientStates: readonly SetupClientState[];
|
2026-07-12 06:34:27 +08:00
|
|
|
readonly remediation?: string;
|
2026-07-13 21:08:33 +00:00
|
|
|
readonly code?: SetupFailureCode;
|
2026-07-12 06:34:27 +08:00
|
|
|
}
|
|
|
|
|
|
2026-10-06 00:50:38 +08:00
|
|
|
/** Whether the requested setup actions still need approval or human repair. */
|
|
|
|
|
export const isSetupFailure = (result: SetupResult): boolean => {
|
|
|
|
|
const status = result.status;
|
|
|
|
|
switch (status) {
|
|
|
|
|
case "planned":
|
|
|
|
|
case "cancelled":
|
|
|
|
|
case "ready":
|
|
|
|
|
return false;
|
|
|
|
|
case "needs_confirmation":
|
|
|
|
|
case "needs_human":
|
|
|
|
|
return true;
|
|
|
|
|
default: {
|
|
|
|
|
const exhaustive: never = status;
|
|
|
|
|
throw new TypeError(
|
|
|
|
|
`Unhandled setup result status: ${String(exhaustive)}`,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-05 23:06:19 +08:00
|
|
|
/** Relevant health and identity evidence for the selected setup scope. */
|
|
|
|
|
export interface SetupDoctorSummary {
|
|
|
|
|
readonly healthy: boolean;
|
|
|
|
|
readonly environment_healthy: boolean;
|
|
|
|
|
readonly scope: DoctorReport["scope"];
|
|
|
|
|
readonly hopperPath?: string;
|
|
|
|
|
readonly availableProviders: readonly string[];
|
|
|
|
|
readonly providerInspections?: DoctorReport["providerInspections"];
|
|
|
|
|
readonly identity?: Pick<
|
|
|
|
|
NonNullable<DoctorReport["identity"]>,
|
|
|
|
|
"skill" | "registrations"
|
|
|
|
|
>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Read-only state for one supported client location. */
|
|
|
|
|
export interface SetupClientState {
|
|
|
|
|
readonly client: SetupClient;
|
|
|
|
|
readonly detected: boolean;
|
|
|
|
|
readonly configured: boolean;
|
|
|
|
|
readonly status: "configured" | "missing" | "needs_configuration" | "invalid";
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-13 15:13:45 +08:00
|
|
|
/** One concrete setup mutation disclosed before approval. */
|
|
|
|
|
export interface SetupAction {
|
2026-07-18 11:59:16 +08:00
|
|
|
readonly id: string;
|
2026-07-13 15:13:45 +08:00
|
|
|
readonly kind: "install_hopper" | "configure_client" | "install_skill";
|
2026-07-18 11:59:16 +08:00
|
|
|
readonly label: string;
|
2026-07-13 15:13:45 +08:00
|
|
|
readonly target: string;
|
|
|
|
|
readonly detail: string;
|
|
|
|
|
readonly external: boolean;
|
2026-07-18 11:59:16 +08:00
|
|
|
readonly operation: "create" | "update" | "install";
|
|
|
|
|
readonly backupPath?: string;
|
|
|
|
|
readonly networkOrigins?: readonly string[];
|
|
|
|
|
readonly commands?: readonly string[];
|
|
|
|
|
readonly integrity?: string;
|
2026-07-13 15:13:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Explicit authorization supplied by an interactive or unattended CLI adapter. */
|
|
|
|
|
export interface SetupOptions {
|
|
|
|
|
readonly approved: boolean;
|
|
|
|
|
readonly installHopper: boolean;
|
|
|
|
|
readonly structured: boolean;
|
2026-07-18 11:59:16 +08:00
|
|
|
readonly proposeHopper?: boolean;
|
|
|
|
|
readonly clientIds?: readonly string[];
|
|
|
|
|
readonly installSkill?: boolean;
|
2026-07-22 20:38:26 +08:00
|
|
|
readonly readinessScope?: DoctorScope;
|
2026-10-05 23:06:19 +08:00
|
|
|
readonly dryRun?: boolean;
|
|
|
|
|
readonly allDetectedClients?: boolean;
|
2026-07-18 11:59:16 +08:00
|
|
|
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[];
|
2026-10-05 23:06:19 +08:00
|
|
|
readonly cancelled?: boolean;
|
2026-07-13 15:13:45 +08:00
|
|
|
}
|
|
|
|
|
|
2026-10-05 23:06:19 +08:00
|
|
|
/** Read-only context shown while selecting clients or reviewing exact actions. */
|
|
|
|
|
export interface SetupConfirmationContext {
|
|
|
|
|
readonly stage: "select" | "confirm";
|
|
|
|
|
readonly clientStates: readonly SetupClientState[];
|
|
|
|
|
readonly selectedClientIds: readonly string[];
|
|
|
|
|
readonly clientSelectionAllowed: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Adapter-owned selection and confirmation for the setup workflow. */
|
2026-07-13 15:13:45 +08:00
|
|
|
export type SetupConfirmation = (
|
|
|
|
|
actions: readonly SetupAction[],
|
2026-10-05 23:06:19 +08:00
|
|
|
context?: SetupConfirmationContext,
|
2026-07-18 11:59:16 +08:00
|
|
|
) => Promise<boolean | SetupConfirmationDecision>;
|
2026-07-13 15:13:45 +08:00
|
|
|
|
2026-07-18 05:18:05 +00:00
|
|
|
/** Discover, approve, and apply setup actions idempotently. */
|
2026-07-12 06:34:27 +08:00
|
|
|
export const runSetup = async (
|
2026-07-13 15:13:45 +08:00
|
|
|
options: SetupOptions,
|
2026-07-12 06:34:27 +08:00
|
|
|
host: SetupHost = systemSetupHost(),
|
2026-07-13 15:13:45 +08:00
|
|
|
confirm?: SetupConfirmation,
|
2026-07-12 06:34:27 +08:00
|
|
|
): Promise<SetupResult> => {
|
2026-07-13 15:13:45 +08:00
|
|
|
const appliedActions: string[] = [];
|
|
|
|
|
let plannedActions: readonly SetupAction[] = [];
|
2026-07-12 06:34:27 +08:00
|
|
|
const clients: Record<string, ClientConfigurationResult> = {};
|
2026-10-05 23:06:19 +08:00
|
|
|
let clientStates: readonly SetupClientState[] = [];
|
|
|
|
|
let readinessScope = options.readinessScope;
|
2026-07-18 04:11:29 +00:00
|
|
|
const fail = (remediation: string) =>
|
2026-07-22 20:38:26 +08:00
|
|
|
setupFailure(
|
|
|
|
|
remediation,
|
2026-10-05 23:06:19 +08:00
|
|
|
[host, plannedActions, appliedActions, clients, clientStates],
|
|
|
|
|
readinessScope,
|
2026-07-22 20:38:26 +08:00
|
|
|
);
|
2026-10-05 23:06:19 +08:00
|
|
|
const unsupported = await hostRemediation(host, false);
|
2026-07-12 23:42:20 +00:00
|
|
|
if (unsupported !== undefined) return fail(unsupported);
|
2026-07-12 09:12:13 +08:00
|
|
|
let hopperPath = await host.hopperPath();
|
2026-07-16 00:02:49 +08:00
|
|
|
let providerEnvironment = await initialProviderEnvironment(host, hopperPath);
|
2026-10-05 23:06:19 +08:00
|
|
|
const discovery = await discoverSetupState({
|
2026-07-15 06:34:25 +00:00
|
|
|
host,
|
2026-07-16 00:02:49 +08:00
|
|
|
providerEnvironment,
|
2026-07-18 11:59:16 +08:00
|
|
|
forceHopperInstall: options.installHopper,
|
2026-10-05 23:06:19 +08:00
|
|
|
proposeHopper:
|
|
|
|
|
options.proposeHopper ?? (confirm !== undefined && !options.structured),
|
2026-07-22 20:38:26 +08:00
|
|
|
doctorScope: options.readinessScope,
|
2026-07-18 11:59:16 +08:00
|
|
|
});
|
2026-10-05 23:06:19 +08:00
|
|
|
clientStates = discovery.clientStates;
|
|
|
|
|
const clientSelectionAllowed =
|
|
|
|
|
options.clientIds === undefined &&
|
|
|
|
|
options.readinessScope?.clients === undefined &&
|
|
|
|
|
options.allDetectedClients !== true &&
|
|
|
|
|
options.installHopper !== true &&
|
|
|
|
|
options.installSkill === undefined;
|
|
|
|
|
const interactiveSelection =
|
|
|
|
|
confirm !== undefined && !options.structured && clientSelectionAllowed;
|
|
|
|
|
let selectedClientIds = options.allDetectedClients
|
|
|
|
|
? discovery.detectedClientIds
|
|
|
|
|
: (options.clientIds ??
|
|
|
|
|
options.readinessScope?.clients ??
|
|
|
|
|
discovery.defaultClientIds);
|
|
|
|
|
let skillSelected =
|
|
|
|
|
options.installSkill === true ||
|
|
|
|
|
(options.installSkill !== false && selectedClientIds.length > 0);
|
|
|
|
|
let installSkill = skillSelected && discovery.skillNeedsInstall;
|
|
|
|
|
let planDiscovery = discovery;
|
|
|
|
|
if (interactiveSelection) {
|
|
|
|
|
const offerSkillAction =
|
|
|
|
|
options.installSkill !== false && discovery.skillNeedsInstall;
|
|
|
|
|
const selectionActions = await planSetupActions({
|
|
|
|
|
discovery,
|
|
|
|
|
host,
|
|
|
|
|
providerEnvironment,
|
|
|
|
|
command: setupRegistrationCommand(host.platform),
|
|
|
|
|
clientIds: [],
|
|
|
|
|
installSkill: offerSkillAction,
|
|
|
|
|
});
|
|
|
|
|
const decision = await confirm(selectionActions.plannedActions, {
|
|
|
|
|
stage: "select",
|
|
|
|
|
clientStates,
|
|
|
|
|
selectedClientIds: discovery.defaultClientIds,
|
|
|
|
|
clientSelectionAllowed,
|
|
|
|
|
});
|
|
|
|
|
if (isSetupDecisionCancelled(decision))
|
|
|
|
|
return setupCancelled(
|
|
|
|
|
selectionActions.plannedActions,
|
|
|
|
|
clients,
|
|
|
|
|
clientStates,
|
|
|
|
|
discovery.initialDoctor,
|
|
|
|
|
);
|
|
|
|
|
const selectedActionIds = new Set(
|
|
|
|
|
typeof decision === "boolean"
|
|
|
|
|
? decision
|
|
|
|
|
? [
|
|
|
|
|
...selectionActions.plannedActions.map(({ id }) => id),
|
|
|
|
|
...discovery.defaultClientIds.map(
|
|
|
|
|
(id) => `configure_client:${id}`,
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
: []
|
|
|
|
|
: decision.selectedActionIds,
|
|
|
|
|
);
|
|
|
|
|
selectedClientIds = [...selectedActionIds]
|
|
|
|
|
.filter((id) => id.startsWith("configure_client:"))
|
|
|
|
|
.map((id) => id.slice("configure_client:".length));
|
|
|
|
|
const proposedInstallAction = selectionActions.plannedActions.some(
|
|
|
|
|
({ id }) => id === "install_hopper",
|
|
|
|
|
);
|
|
|
|
|
planDiscovery = {
|
|
|
|
|
...discovery,
|
|
|
|
|
installHopper:
|
|
|
|
|
options.installHopper ||
|
|
|
|
|
(proposedInstallAction && selectedActionIds.has("install_hopper")),
|
|
|
|
|
};
|
|
|
|
|
skillSelected =
|
|
|
|
|
options.installSkill === true ||
|
|
|
|
|
(selectedActionIds.has("install_skill") &&
|
|
|
|
|
selectedClientIds.length === 0) ||
|
|
|
|
|
(options.installSkill !== false && selectedClientIds.length > 0);
|
|
|
|
|
installSkill = skillSelected && discovery.skillNeedsInstall;
|
|
|
|
|
}
|
|
|
|
|
const planned = await planSetupActions({
|
|
|
|
|
discovery: planDiscovery,
|
|
|
|
|
host,
|
|
|
|
|
providerEnvironment,
|
|
|
|
|
command: setupRegistrationCommand(host.platform),
|
|
|
|
|
clientIds: selectedClientIds,
|
|
|
|
|
installSkill,
|
|
|
|
|
});
|
|
|
|
|
plannedActions = planned.plannedActions;
|
|
|
|
|
if (planned.blocker !== undefined) return fail(planned.blocker);
|
|
|
|
|
const hopperBlocker = await hostRemediation(
|
|
|
|
|
host,
|
|
|
|
|
planDiscovery.installHopper,
|
|
|
|
|
);
|
|
|
|
|
if (hopperBlocker !== undefined) return fail(hopperBlocker);
|
|
|
|
|
const planSelection = {
|
|
|
|
|
installHopper: planDiscovery.installHopper,
|
|
|
|
|
installSkill,
|
|
|
|
|
skillSelected,
|
|
|
|
|
selectedClients: planned.selectedClients,
|
|
|
|
|
clientsToConfigure: planned.clientsToConfigure,
|
|
|
|
|
};
|
|
|
|
|
readinessScope = resolvedReadinessScope(
|
|
|
|
|
options.readinessScope,
|
|
|
|
|
planSelection,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (options.dryRun === true)
|
|
|
|
|
return {
|
|
|
|
|
status: "planned",
|
|
|
|
|
plannedActions,
|
|
|
|
|
appliedActions,
|
|
|
|
|
clients,
|
|
|
|
|
doctor: summarizeDoctor(discovery.initialDoctor),
|
|
|
|
|
clientStates,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let approved = options.approved || plannedActions.length === 0;
|
|
|
|
|
let interactiveApproval = false;
|
|
|
|
|
if (!approved && confirm !== undefined && !options.structured) {
|
|
|
|
|
const decision = await confirm?.(plannedActions, {
|
|
|
|
|
stage: "confirm",
|
|
|
|
|
clientStates,
|
|
|
|
|
selectedClientIds,
|
|
|
|
|
clientSelectionAllowed: false,
|
|
|
|
|
});
|
|
|
|
|
if (decision !== undefined) {
|
|
|
|
|
if (isSetupDecisionCancelled(decision))
|
|
|
|
|
return setupCancelled(
|
|
|
|
|
plannedActions,
|
|
|
|
|
clients,
|
|
|
|
|
clientStates,
|
|
|
|
|
discovery.initialDoctor,
|
|
|
|
|
);
|
|
|
|
|
approved = typeof decision === "boolean" ? decision : decision.approved;
|
|
|
|
|
interactiveApproval = approved;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!approved)
|
2026-07-13 15:13:45 +08:00
|
|
|
return {
|
2026-10-05 23:06:19 +08:00
|
|
|
status: confirm === undefined ? "needs_confirmation" : "cancelled",
|
2026-07-13 15:13:45 +08:00
|
|
|
plannedActions,
|
|
|
|
|
appliedActions,
|
|
|
|
|
clients,
|
2026-10-05 23:06:19 +08:00
|
|
|
doctor: summarizeDoctor(discovery.initialDoctor),
|
|
|
|
|
clientStates,
|
|
|
|
|
...(confirm === undefined
|
|
|
|
|
? {
|
|
|
|
|
remediation:
|
|
|
|
|
"Review the setup plan, then rerun interactively or with --yes.",
|
|
|
|
|
}
|
|
|
|
|
: {}),
|
2026-07-13 15:13:45 +08:00
|
|
|
};
|
|
|
|
|
|
2026-10-05 23:06:19 +08:00
|
|
|
let selectedClients: readonly SetupClient[] =
|
|
|
|
|
planSelection.clientsToConfigure;
|
2026-07-18 05:18:05 +00:00
|
|
|
if (
|
2026-10-05 23:06:19 +08:00
|
|
|
planSelection.installHopper &&
|
|
|
|
|
(interactiveApproval || options.installHopper)
|
2026-07-18 05:18:05 +00:00
|
|
|
) {
|
|
|
|
|
const install = await installHopperAction({
|
2026-07-15 06:34:25 +00:00
|
|
|
host,
|
2026-07-18 05:18:05 +00:00
|
|
|
options,
|
|
|
|
|
plannedActions,
|
|
|
|
|
appliedActions,
|
|
|
|
|
clients,
|
2026-10-05 23:06:19 +08:00
|
|
|
selectedClients,
|
2026-07-16 00:02:49 +08:00
|
|
|
providerEnvironment,
|
2026-10-05 23:06:19 +08:00
|
|
|
doctorScope: readinessScope,
|
|
|
|
|
clientStates,
|
2026-07-18 05:18:05 +00:00
|
|
|
});
|
|
|
|
|
if ("failure" in install) return install.failure;
|
2026-10-05 23:06:19 +08:00
|
|
|
({ hopperPath, providerEnvironment, selectedClients } = install);
|
2026-07-12 06:34:27 +08:00
|
|
|
}
|
2026-07-13 18:20:40 +08:00
|
|
|
const clientFailure = await configureDetectedClients({
|
|
|
|
|
host,
|
2026-10-05 23:06:19 +08:00
|
|
|
detectedClients: selectedClients,
|
2026-07-16 00:02:49 +08:00
|
|
|
providerEnvironment,
|
2026-10-05 23:06:19 +08:00
|
|
|
command: setupRegistrationCommand(host.platform),
|
2026-07-13 18:20:40 +08:00
|
|
|
clients,
|
|
|
|
|
appliedActions,
|
2026-07-18 11:59:16 +08:00
|
|
|
...(options.onProgress === undefined
|
|
|
|
|
? {}
|
|
|
|
|
: { onProgress: options.onProgress }),
|
2026-07-13 18:20:40 +08:00
|
|
|
});
|
|
|
|
|
if (clientFailure !== undefined) return fail(clientFailure);
|
2026-07-18 05:18:05 +00:00
|
|
|
if (
|
2026-10-05 23:06:19 +08:00
|
|
|
planSelection.installSkill &&
|
2026-07-18 05:18:05 +00:00
|
|
|
!(await installSkillAction(host, options, appliedActions))
|
|
|
|
|
)
|
|
|
|
|
return fail(
|
|
|
|
|
"REA analysis skill could not be installed or verified. Check permissions for `~/.agents/skills`, then rerun setup.",
|
2026-07-18 11:59:16 +08:00
|
|
|
);
|
2026-10-05 23:06:19 +08:00
|
|
|
const doctor = summarizeDoctor(await host.doctor(readinessScope));
|
2026-07-13 20:50:01 +00:00
|
|
|
const remediation = finalSetupRemediation(
|
|
|
|
|
host.platform,
|
|
|
|
|
appliedActions.includes("installed_hopper"),
|
|
|
|
|
doctor.healthy,
|
|
|
|
|
hopperPath,
|
|
|
|
|
);
|
2026-07-12 06:34:27 +08:00
|
|
|
return {
|
2026-07-13 20:50:01 +00:00
|
|
|
status: remediation === undefined ? "ready" : "needs_human",
|
2026-07-13 15:13:45 +08:00
|
|
|
plannedActions,
|
|
|
|
|
appliedActions,
|
2026-07-12 06:34:27 +08:00
|
|
|
clients,
|
|
|
|
|
doctor,
|
2026-10-05 23:06:19 +08:00
|
|
|
clientStates,
|
2026-07-13 20:50:01 +00:00
|
|
|
...(remediation === undefined ? {} : { remediation }),
|
2026-07-12 06:34:27 +08:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2026-07-18 05:18:05 +00:00
|
|
|
const installHopperAction = async (input: {
|
|
|
|
|
readonly host: SetupHost;
|
|
|
|
|
readonly options: SetupOptions;
|
|
|
|
|
readonly plannedActions: readonly SetupAction[];
|
|
|
|
|
readonly appliedActions: string[];
|
|
|
|
|
readonly clients: Readonly<Record<string, ClientConfigurationResult>>;
|
2026-10-05 23:06:19 +08:00
|
|
|
readonly selectedClients: readonly SetupClient[];
|
2026-07-18 05:18:05 +00:00
|
|
|
readonly providerEnvironment: SetupProviderEnvironment;
|
2026-07-22 20:38:26 +08:00
|
|
|
readonly doctorScope: DoctorScope | undefined;
|
2026-10-05 23:06:19 +08:00
|
|
|
readonly clientStates: readonly SetupClientState[];
|
2026-07-18 05:18:05 +00:00
|
|
|
}) => {
|
|
|
|
|
const label = "Hopper deep-analysis provider";
|
|
|
|
|
emitProgress(input.options, {
|
|
|
|
|
actionId: "install_hopper",
|
|
|
|
|
label,
|
|
|
|
|
state: "started",
|
|
|
|
|
});
|
|
|
|
|
const installed = await input.host.installHopper(input.options.installHopper);
|
|
|
|
|
if (installed.status === "failed") {
|
|
|
|
|
emitProgress(input.options, {
|
|
|
|
|
actionId: "install_hopper",
|
|
|
|
|
label,
|
|
|
|
|
state: "failed",
|
|
|
|
|
detail: installed.remediation,
|
|
|
|
|
});
|
|
|
|
|
return {
|
|
|
|
|
failure: {
|
|
|
|
|
status: "needs_human" as const,
|
|
|
|
|
plannedActions: input.plannedActions,
|
|
|
|
|
appliedActions: input.appliedActions,
|
|
|
|
|
clients: input.clients,
|
2026-10-05 23:06:19 +08:00
|
|
|
doctor: summarizeDoctor(await input.host.doctor(input.doctorScope)),
|
|
|
|
|
clientStates: input.clientStates,
|
2026-07-18 05:18:05 +00:00
|
|
|
code: installed.code,
|
|
|
|
|
remediation: installed.remediation,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
input.appliedActions.push("installed_hopper");
|
|
|
|
|
emitProgress(input.options, {
|
|
|
|
|
actionId: "install_hopper",
|
|
|
|
|
label,
|
|
|
|
|
state: "completed",
|
|
|
|
|
detail: installed.launcherPath,
|
|
|
|
|
});
|
|
|
|
|
const providerEnvironment = {
|
|
|
|
|
...input.providerEnvironment,
|
|
|
|
|
HOPPER_LAUNCHER_PATH: installed.launcherPath,
|
|
|
|
|
};
|
|
|
|
|
return {
|
|
|
|
|
hopperPath: installed.launcherPath,
|
|
|
|
|
providerEnvironment,
|
2026-10-05 23:06:19 +08:00
|
|
|
selectedClients: await filterClientsNeedingConfigure(
|
2026-07-18 05:18:05 +00:00
|
|
|
input.host,
|
2026-10-05 23:06:19 +08:00
|
|
|
input.selectedClients,
|
2026-07-18 05:18:05 +00:00
|
|
|
providerEnvironment,
|
2026-10-05 23:06:19 +08:00
|
|
|
setupRegistrationCommand(input.host.platform),
|
2026-07-18 05:18:05 +00:00
|
|
|
),
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const installSkillAction = async (
|
|
|
|
|
host: SetupHost,
|
|
|
|
|
options: SetupOptions,
|
|
|
|
|
appliedActions: string[],
|
|
|
|
|
): Promise<boolean> => {
|
|
|
|
|
const label = "REA reverse-engineering skill";
|
|
|
|
|
emitProgress(options, {
|
|
|
|
|
actionId: "install_skill",
|
|
|
|
|
label,
|
|
|
|
|
state: "started",
|
|
|
|
|
});
|
|
|
|
|
const skill = await host.installSkill();
|
|
|
|
|
if (skill === "failed") {
|
|
|
|
|
emitProgress(options, {
|
|
|
|
|
actionId: "install_skill",
|
|
|
|
|
label,
|
|
|
|
|
state: "failed",
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (skill === "installed") appliedActions.push("installed_skill");
|
|
|
|
|
emitProgress(options, {
|
|
|
|
|
actionId: "install_skill",
|
|
|
|
|
label,
|
|
|
|
|
state: skill === "installed" ? "completed" : "warning",
|
|
|
|
|
...(skill === "unchanged" ? { detail: "Already current" } : {}),
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
2026-07-18 04:11:29 +00:00
|
|
|
const setupFailure = async (
|
|
|
|
|
remediation: string,
|
2026-10-05 23:06:19 +08:00
|
|
|
[host, plannedActions, appliedActions, clients, clientStates]: readonly [
|
2026-07-18 04:11:29 +00:00
|
|
|
SetupHost,
|
|
|
|
|
readonly SetupAction[],
|
|
|
|
|
readonly string[],
|
|
|
|
|
Readonly<Record<string, ClientConfigurationResult>>,
|
2026-10-05 23:06:19 +08:00
|
|
|
readonly SetupClientState[],
|
2026-07-18 04:11:29 +00:00
|
|
|
],
|
2026-07-22 20:38:26 +08:00
|
|
|
scope?: DoctorScope,
|
2026-10-05 23:06:19 +08:00
|
|
|
): Promise<SetupResult> => {
|
|
|
|
|
return {
|
|
|
|
|
status: "needs_human",
|
|
|
|
|
plannedActions,
|
|
|
|
|
appliedActions,
|
|
|
|
|
clients,
|
|
|
|
|
doctor: summarizeDoctor(await host.doctor(scope)),
|
|
|
|
|
clientStates,
|
|
|
|
|
remediation,
|
|
|
|
|
};
|
|
|
|
|
};
|
2026-07-18 04:11:29 +00:00
|
|
|
|
2026-07-18 05:18:05 +00:00
|
|
|
const emitProgress = (options: SetupOptions, event: SetupProgressEvent): void =>
|
|
|
|
|
options.onProgress?.(event);
|
2026-07-18 11:59:16 +08:00
|
|
|
|
2026-07-14 22:00:42 +00:00
|
|
|
const filterClientsNeedingConfigure = async (
|
|
|
|
|
host: SetupHost,
|
|
|
|
|
detectedClients: readonly SetupClient[],
|
2026-07-16 00:02:49 +08:00
|
|
|
providerEnvironment: SetupProviderEnvironment,
|
2026-07-14 22:00:42 +00:00
|
|
|
command: readonly string[],
|
|
|
|
|
): Promise<readonly SetupClient[]> => {
|
|
|
|
|
const needs = await Promise.all(
|
|
|
|
|
detectedClients.map((client) =>
|
2026-07-16 00:02:49 +08:00
|
|
|
host.clientNeedsConfigure(client, providerEnvironment, command),
|
2026-07-14 22:00:42 +00:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
return detectedClients.filter((_, index) => needs[index]);
|
|
|
|
|
};
|
|
|
|
|
|
2026-07-16 00:02:49 +08:00
|
|
|
const initialProviderEnvironment = async (
|
|
|
|
|
host: SetupHost,
|
|
|
|
|
hopperPath: string | undefined,
|
|
|
|
|
): Promise<SetupProviderEnvironment> => ({
|
|
|
|
|
...(await host.providerEnvironment?.()),
|
|
|
|
|
...(hopperPath === undefined ? {} : { HOPPER_LAUNCHER_PATH: hopperPath }),
|
|
|
|
|
});
|
|
|
|
|
|
2026-07-13 20:50:01 +00:00
|
|
|
const finalSetupRemediation = (
|
|
|
|
|
platform: NodeJS.Platform,
|
|
|
|
|
installedHopper: boolean,
|
|
|
|
|
healthy: boolean,
|
|
|
|
|
hopperPath: string | undefined,
|
|
|
|
|
): string | undefined => {
|
|
|
|
|
if (platform === "darwin" && installedHopper)
|
|
|
|
|
return "Open Hopper, choose its demo mode or activate a license, then rerun rea doctor --json.";
|
|
|
|
|
if (healthy) return undefined;
|
|
|
|
|
return hopperPath === undefined
|
|
|
|
|
? "Hopper is optional for non-Hopper providers. Rerun with --yes --install-hopper for deep native analysis."
|
|
|
|
|
: "Run rea doctor and apply each reported remediation.";
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-05 23:06:19 +08:00
|
|
|
const isSetupDecisionCancelled = (
|
|
|
|
|
decision: boolean | SetupConfirmationDecision,
|
|
|
|
|
): boolean =>
|
|
|
|
|
typeof decision === "boolean" ? !decision : decision.cancelled === true;
|
|
|
|
|
|
|
|
|
|
const setupCancelled = (
|
|
|
|
|
plannedActions: readonly SetupAction[],
|
|
|
|
|
clients: Readonly<Record<string, ClientConfigurationResult>>,
|
|
|
|
|
clientStates: readonly SetupClientState[],
|
|
|
|
|
doctor: DoctorReport,
|
|
|
|
|
): SetupResult => ({
|
|
|
|
|
status: "cancelled",
|
|
|
|
|
plannedActions,
|
|
|
|
|
appliedActions: [],
|
|
|
|
|
clients,
|
|
|
|
|
doctor: summarizeDoctor(doctor),
|
|
|
|
|
clientStates,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const resolvedReadinessScope = (
|
|
|
|
|
requested: DoctorScope | undefined,
|
|
|
|
|
selection: {
|
|
|
|
|
readonly selectedClients: readonly SetupClient[];
|
|
|
|
|
readonly installHopper: boolean;
|
|
|
|
|
readonly skillSelected?: boolean;
|
|
|
|
|
},
|
|
|
|
|
): DoctorScope => ({
|
|
|
|
|
clients: selection.selectedClients.map(({ name }) => name),
|
|
|
|
|
providers: selection.installHopper
|
|
|
|
|
? ["hopper"]
|
|
|
|
|
: (requested?.providers ?? []),
|
|
|
|
|
skill: selection.skillSelected === true || requested?.skill === true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const summarizeDoctor = (report: DoctorReport): SetupDoctorSummary => ({
|
|
|
|
|
healthy: report.healthy,
|
|
|
|
|
environment_healthy: report.environment_healthy,
|
|
|
|
|
scope: report.scope,
|
|
|
|
|
availableProviders: [
|
|
|
|
|
...(report.hopperPath !== undefined &&
|
|
|
|
|
report.checks
|
|
|
|
|
.filter(({ name }) => name.startsWith("hopper"))
|
|
|
|
|
.every(({ ok }) => ok)
|
|
|
|
|
? ["hopper"]
|
|
|
|
|
: []),
|
|
|
|
|
...(report.providerInspections ?? [])
|
|
|
|
|
.filter(({ available }) => available)
|
|
|
|
|
.map(({ id }) => id),
|
|
|
|
|
],
|
|
|
|
|
...(report.hopperPath === undefined ? {} : { hopperPath: report.hopperPath }),
|
|
|
|
|
...(report.providerInspections === undefined
|
|
|
|
|
? {}
|
|
|
|
|
: { providerInspections: report.providerInspections }),
|
|
|
|
|
...(report.identity === undefined
|
|
|
|
|
? {}
|
|
|
|
|
: {
|
|
|
|
|
identity: {
|
|
|
|
|
skill: report.identity.skill,
|
|
|
|
|
registrations: report.identity.registrations,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
2026-07-12 23:42:20 +00:00
|
|
|
const hostRemediation = async (
|
|
|
|
|
host: SetupHost,
|
2026-10-05 23:06:19 +08:00
|
|
|
installHopper: boolean,
|
2026-07-12 23:42:20 +00:00
|
|
|
): Promise<string | undefined> => {
|
2026-07-13 15:13:45 +08:00
|
|
|
if (!supportsNodeVersion(host.nodeVersion))
|
|
|
|
|
return "Install Node.js 22.19+ or 24.11+ and rerun setup.";
|
2026-10-05 23:06:19 +08:00
|
|
|
if (!installHopper) return undefined;
|
|
|
|
|
if (host.platform !== "darwin" && host.platform !== "linux")
|
|
|
|
|
return "REA supports Hopper on macOS and selected 64-bit Linux distributions.";
|
2026-07-12 23:42:20 +00:00
|
|
|
if (host.platform === "darwin") {
|
|
|
|
|
const version = await host.macosVersion();
|
|
|
|
|
return version === undefined || major(version) < 12
|
|
|
|
|
? "Upgrade to macOS 12 or newer."
|
|
|
|
|
: undefined;
|
|
|
|
|
}
|
2026-07-16 00:02:49 +08:00
|
|
|
if ((await host.linuxDistribution())?.supported === true) return undefined;
|
|
|
|
|
return "Automated Hopper setup supports Ubuntu 24.04+, Fedora 41+, and 64-bit Arch Linux; configure an existing supported provider instead.";
|
2026-07-12 23:42:20 +00:00
|
|
|
};
|
|
|
|
|
|
2026-07-13 15:13:45 +08:00
|
|
|
/** Production setup effects for Hopper, agent configuration, and the canonical skill directory. */
|
2026-07-16 00:02:49 +08:00
|
|
|
export const systemSetupHost = (
|
|
|
|
|
doctorHost: DoctorHost = systemDoctorHost(),
|
|
|
|
|
): SetupHost => {
|
2026-10-06 00:50:38 +08:00
|
|
|
const platform = doctorHost.platform;
|
2026-07-12 06:34:27 +08:00
|
|
|
return {
|
2026-10-06 00:50:38 +08:00
|
|
|
platform,
|
2026-07-12 06:34:27 +08:00
|
|
|
nodeVersion: process.versions.node,
|
|
|
|
|
macosVersion: () => doctorHost.macosVersion(),
|
2026-07-12 23:42:20 +00:00
|
|
|
linuxDistribution: readLinuxDistribution,
|
2026-07-12 06:34:27 +08:00
|
|
|
hopperPath: async () => (await runDoctor(undefined, doctorHost)).hopperPath,
|
2026-07-16 00:02:49 +08:00
|
|
|
providerEnvironment: async () => {
|
|
|
|
|
const diagnosis = await runDoctor(undefined, doctorHost);
|
|
|
|
|
return {
|
|
|
|
|
...providerRegistrationEnvironment(diagnosis.providerInspections ?? []),
|
|
|
|
|
...(diagnosis.hopperPath === undefined
|
|
|
|
|
? {}
|
|
|
|
|
: { HOPPER_LAUNCHER_PATH: diagnosis.hopperPath }),
|
|
|
|
|
};
|
|
|
|
|
},
|
2026-07-15 06:52:52 +00:00
|
|
|
installHopper: async (replaceExisting) => {
|
2026-07-13 15:13:45 +08:00
|
|
|
const result =
|
2026-10-06 00:50:38 +08:00
|
|
|
platform === "linux"
|
2026-07-13 15:13:45 +08:00
|
|
|
? await installLinuxHopper()
|
2026-07-15 06:52:52 +00:00
|
|
|
: await installMacHopper({ replaceExisting });
|
2026-07-13 21:08:33 +00:00
|
|
|
if (result.status === "installed") return result;
|
|
|
|
|
return setupInstallFailure(result.reason);
|
2026-07-13 15:13:45 +08:00
|
|
|
},
|
2026-07-12 23:42:20 +00:00
|
|
|
detectedClients: () => detectClients(homedir()),
|
2026-10-05 23:06:19 +08:00
|
|
|
supportedClients: () => Promise.resolve(supportedClients(homedir())),
|
2026-07-16 00:02:49 +08:00
|
|
|
configureClient: (client, providerEnvironment, command) =>
|
2026-07-12 23:42:20 +00:00
|
|
|
client.format === "unsupported"
|
|
|
|
|
? Promise.resolve({ status: "skipped" })
|
2026-10-05 23:06:19 +08:00
|
|
|
: configureClientConfiguration(client, providerEnvironment, command),
|
2026-07-16 00:02:49 +08:00
|
|
|
clientNeedsConfigure: (client, providerEnvironment, command) =>
|
|
|
|
|
clientConfigurationAligned(client, providerEnvironment, command).then(
|
2026-07-14 22:00:42 +00:00
|
|
|
(aligned) => !aligned,
|
|
|
|
|
),
|
2026-07-18 11:59:16 +08:00
|
|
|
inspectClientConfiguration: inspectClientConfiguration,
|
2026-07-14 20:14:58 +00:00
|
|
|
skillNeedsInstall: () => canonicalSkillNeedsInstall(homedir()),
|
2026-07-12 06:34:27 +08:00
|
|
|
installSkill: () => installCanonicalSkill(homedir()),
|
2026-07-22 20:38:26 +08:00
|
|
|
doctor: (scope) => runDoctor(undefined, doctorHost, scope),
|
2026-07-12 06:34:27 +08:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-05 23:06:19 +08:00
|
|
|
/** Detect supported agents from their config files or stable installation markers. */
|
2026-07-12 23:42:20 +00:00
|
|
|
export const detectClients = async (
|
2026-07-12 06:34:27 +08:00
|
|
|
home: string,
|
|
|
|
|
): Promise<readonly SetupClient[]> => {
|
|
|
|
|
const detected: SetupClient[] = [];
|
2026-10-05 23:06:19 +08:00
|
|
|
for (const candidate of supportedClients(home)) {
|
|
|
|
|
const [hasConfig, hasMarker] = await Promise.all([
|
|
|
|
|
exists(candidate.configPath),
|
|
|
|
|
candidate.markerPath === undefined ? false : exists(candidate.markerPath),
|
|
|
|
|
]);
|
|
|
|
|
if (hasConfig || hasMarker) detected.push(candidate);
|
|
|
|
|
}
|
2026-07-12 06:34:27 +08:00
|
|
|
return detected;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const major = (version: string): number =>
|
|
|
|
|
Number.parseInt(version.split(".")[0] ?? "0", 10);
|
|
|
|
|
const exists = async (path: string): Promise<boolean> => {
|
|
|
|
|
try {
|
|
|
|
|
await access(path);
|
|
|
|
|
return true;
|
|
|
|
|
} catch {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|