mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 17:44:27 +00:00
* feat(config): persist provider settings in a user config file Providers currently rediscover install paths from scratch in every process, so a path set once (for example GHIDRA_INSTALL_DIR) silently reverts on the next run. Introduce ~/.config/rea/rea.json as the user-owned persistence layer and merge it into the environment snapshot before configuration parsing, keeping env > config file > auto-detect precedence on both the CLI and MCP entry points. Add a rea config command (list/get/set/unset) as the write surface, reporting the effective value and where it came from. * fix(config): address review findings on persistence safety and CLI surface - stage config writes beside the file and rename into place so an interrupted write cannot leave partial JSON (greptile #4, codex #11) - convert unreadable config files into configuration errors on the CLI seam instead of escaping raw filesystem errors (greptile #5, codex #15) - keep injected runtimes without a config root isolated from the host account's rea.json (codex #18) - surface the config file error on stderr when doctor falls back to the raw environment (greptile #3, codex #16) - route the config command through logCliCommand and return documents so --json stays parseable and failures exit non-zero (greptile #2, codex #10) - reject empty --set values, unknown --set/--unset/--get names, and --get combined with mutations (greptile #1/#7, codex #9/#12/#13/#17) - cover the new behavior in the boundary tests and stop leaking one temporary home per run (greptile #8) * fix(config): validate and back up persisted provider settings * fix(config): keep saved provider defaults out of client registrations * fix(config): preserve provider discovery and budgets for saved settings * fix(config): check only settings needed by the IDA deadline lookup * fix(config): share effective provider settings and verify config file reads * fix(doctor): share selected settings with Hopper and ILSpy probes * fix(config): resolve the destination of first-time saves * fix(doctor): preserve unresolved provider location inputs * fix(doctor): honor inherited IDA deadline overrides * fix(config): show empty environment overrides * fix(setup): preserve client-selected saved configuration roots --------- Co-authored-by: Jackzigen <zigenhan@gmail.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
115 lines
3.7 KiB
TypeScript
115 lines
3.7 KiB
TypeScript
import { readdirSync, type Dirent } from "node:fs";
|
|
import { readdir } from "node:fs/promises";
|
|
import { posix } from "node:path";
|
|
import { appendCallerPath } from "../filesystem/callerPath.js";
|
|
|
|
export const MAC_HOPPER_APPLICATION_DIRECTORY = "/Applications";
|
|
export const MAC_HOPPER_APPLICATION_NAME = "Hopper Disassembler.app";
|
|
export const MAC_HOPPER_USER_APPLICATIONS_DIRECTORY = "Applications";
|
|
|
|
export const MAC_HOPPER_SYSTEM_LAUNCHER = posix.join(
|
|
MAC_HOPPER_APPLICATION_DIRECTORY,
|
|
MAC_HOPPER_APPLICATION_NAME,
|
|
"Contents/MacOS/hopper",
|
|
);
|
|
|
|
export const macHopperUserApplicationPath = (homeDirectory: string): string =>
|
|
appendCallerPath(
|
|
homeDirectory,
|
|
`${MAC_HOPPER_USER_APPLICATIONS_DIRECTORY}/${MAC_HOPPER_APPLICATION_NAME}`,
|
|
"darwin",
|
|
);
|
|
|
|
export const macHopperApplicationRoots = (
|
|
homeDirectory: string,
|
|
): readonly string[] => [
|
|
MAC_HOPPER_APPLICATION_DIRECTORY,
|
|
appendCallerPath(
|
|
homeDirectory,
|
|
MAC_HOPPER_USER_APPLICATIONS_DIRECTORY,
|
|
"darwin",
|
|
),
|
|
];
|
|
|
|
export const macHopperCanonicalLauncherCandidates = (
|
|
homeDirectory: string | undefined,
|
|
): readonly string[] => [
|
|
MAC_HOPPER_SYSTEM_LAUNCHER,
|
|
...(homeDirectory === undefined
|
|
? []
|
|
: [
|
|
appendCallerPath(
|
|
macHopperUserApplicationPath(homeDirectory),
|
|
"Contents/MacOS/hopper",
|
|
"darwin",
|
|
),
|
|
]),
|
|
];
|
|
|
|
/** Build deterministic candidates from the discovered app bundle names. */
|
|
const macHopperRenamedLauncherCandidates = (
|
|
homeDirectory: string,
|
|
bundleNamesByRoot: ReadonlyMap<string, readonly string[]>,
|
|
): readonly string[] =>
|
|
macHopperApplicationRoots(homeDirectory).flatMap((root) =>
|
|
[...new Set(bundleNamesByRoot.get(root) ?? [])]
|
|
.filter(
|
|
(name) =>
|
|
/^Hopper.*\.app$/iu.test(name) &&
|
|
name.toLocaleLowerCase("en-US") !==
|
|
MAC_HOPPER_APPLICATION_NAME.toLocaleLowerCase("en-US"),
|
|
)
|
|
.sort()
|
|
.map((name) =>
|
|
appendCallerPath(root, `${name}/Contents/MacOS/hopper`, "darwin"),
|
|
),
|
|
);
|
|
|
|
// A linked application bundle retains its selected spelling. Runtime and
|
|
// doctor validate the executable beneath each candidate, rejecting dangling
|
|
// links and links to ordinary files without interpreting the bundle again.
|
|
const possibleBundleNames = (entries: readonly Dirent[]): readonly string[] =>
|
|
entries
|
|
.filter((entry) => entry.isDirectory() || entry.isSymbolicLink())
|
|
.map(({ name }) => name);
|
|
|
|
const localBundleNames = (root: string): readonly string[] => {
|
|
try {
|
|
return possibleBundleNames(readdirSync(root, { withFileTypes: true }));
|
|
} catch (cause: unknown) {
|
|
// Missing or unreadable optional app directories contain no candidates.
|
|
void cause;
|
|
return [];
|
|
}
|
|
};
|
|
|
|
/** Yield renamed bundles from the local filesystem, reading each root only if needed. */
|
|
export function* localMacHopperRenamedLauncherCandidates(
|
|
homeDirectory: string,
|
|
): Generator<string> {
|
|
for (const root of macHopperApplicationRoots(homeDirectory))
|
|
yield* macHopperRenamedLauncherCandidates(
|
|
homeDirectory,
|
|
new Map([[root, localBundleNames(root)]]),
|
|
);
|
|
}
|
|
|
|
/** Read the same renamed bundles without blocking the event loop, for doctor. */
|
|
export const readMacHopperRenamedLauncherCandidates = async (
|
|
homeDirectory: string,
|
|
): Promise<readonly string[]> => {
|
|
const bundleNamesByRoot = new Map<string, readonly string[]>();
|
|
for (const root of macHopperApplicationRoots(homeDirectory)) {
|
|
try {
|
|
bundleNamesByRoot.set(
|
|
root,
|
|
possibleBundleNames(await readdir(root, { withFileTypes: true })),
|
|
);
|
|
} catch (cause: unknown) {
|
|
// Missing or unreadable optional app directories contain no candidates.
|
|
void cause;
|
|
}
|
|
}
|
|
return macHopperRenamedLauncherCandidates(homeDirectory, bundleNamesByRoot);
|
|
};
|