Files
reverse-engineering-anything/src/application/JunieClientSettings.ts
T
morluto 5f718ce30e refactor(kernel): give error-message, byte-hex and SHA-256 hex helpers one owner in a new src/kernel layer (#11542)
* refactor(kernel): give error-to-message text one owner in a new src/kernel layer

* fix(kernel): keep the regex worker's own error text inside its isolated source

* refactor(kernel): exclude copies that run in another realm from the error-message guard by name

The regex worker's source string and the page.evaluate fetch in PlaywrightScenarioRequest cannot import errorMessage. The guard now names them, so the counted baseline does not invite a later slice to rewrite them.

* refactor(kernel): migrate the long tail of inline error-message copies to errorMessage (#11552)

Every provider and adapter folder with six or fewer copies now calls errorMessage from src/kernel. Local helpers whose whole body was the copy (failureMessage, gdbErrorMessage, message, describe, reasonOf, recoveryFailureMessage and four local errorMessage definitions) are removed and their call sites call the owner.

Refs #11548

* refactor(kernel): give byte-to-hex formatting one owner in src/kernel (#11560)

byteToHex returns the two lowercase hexadecimal digits of one byte. All eight inline copies (native, contracts, domain firmware and desktop, pcap) call it, keeping their own 0x, % or \x notation, and a counted guard with an empty baseline keeps new copies out.

Refs #11548

* refactor(kernel): give one-shot SHA-256 hex digests one owner in src/kernel (#11562)

sha256Hex digests one in-memory value. A counted guard records the one-shot createHash("sha256").update(x).digest("hex") chains (115 in 101 files) and the first slice migrates domain, contracts and process (35 copies), removing local wrappers (sha256, sha256Text, hash) and the exported sha256Text. Incremental and streamed hashing is not counted.

Refs #11548

* refactor(kernel): migrate the application layer's inline error-message copies to errorMessage (#11563)

All 69 copies in src/application call errorMessage from src/kernel. Local helpers whose whole body was the copy (errorDetail, causeReason and five local errorMessage definitions) are removed and their call sites call the owner.

Refs #11548

* refactor(kernel): migrate the native provider's inline error-message copies to errorMessage (#11567)

All 49 copies in src/native call errorMessage from src/kernel. The local errorReason helpers in LldbCallTracer and LldbRetainedObservations, whose whole body was the copy, are removed and their call sites call the owner.

Refs #11548

* refactor(kernel): migrate the remaining inline error-message copies to errorMessage (#11569)
2026-11-16 07:05:30 +08:00

80 lines
3.2 KiB
TypeScript

import type { ArtifactResourceScope } from "../resources/index.js";
import { err, ok, type Result } from "../domain/result.js";
import { clientConfigurationRecordSchema } from "./ClientConfigurationDocument.js";
import {
readConfigurationText,
type ClientConfigurationFileError,
} from "./ClientConfigurationFiles.js";
import { errorMessage } from "../kernel/errorMessage.js";
/**
* Inputs that decide whether Junie loads its default user MCP location. They
* are resolved with the client's row; only the user configuration file is
* read when a registration is inspected or written.
*/
export interface JunieLocationSettings {
/** `$JUNIE_HOME/config.json`, which can set `mcp-default-locations`. */
readonly userConfigPath: string;
readonly mcpDefaultLocations?: string;
readonly configLocation?: string;
readonly configDefaultLocations?: string;
}
/**
* Why Junie would not load its default user MCP file, if it would not. An
* extra configuration location REA cannot inspect leaves that unknown, which
* also blocks. A command-line `--mcp-default-locations=false` is invisible
* to REA.
*/
export const readJunieLocationBlock = async (
settings: JunieLocationSettings,
resources?: ArtifactResourceScope,
): Promise<Result<string | undefined, ClientConfigurationFileError>> => {
if (settings.mcpDefaultLocations?.toLowerCase() === "false")
return ok(
"Junie's default MCP locations are disabled by JUNIE_MCP_DEFAULT_LOCATIONS, so Junie does not load this registration.",
);
if (settings.configLocation)
return ok(
"Cannot determine Junie's MCP location selection while JUNIE_CONFIG_LOCATION is set. Inspect the additional Junie configuration before registering.",
);
if (settings.configDefaultLocations?.toLowerCase() === "false")
return ok(undefined);
const read = await readConfigurationText(settings.userConfigPath, resources);
if (!read.ok)
return err({
...read.error,
detail: `Cannot inspect Junie's user configuration to determine its MCP locations. ${read.error.detail}`,
});
if (read.value === undefined) return ok(undefined);
// Junie reads config.json as strict JSON: comments, trailing commas or an
// empty file leave its MCP location choice unknown rather than default.
let parsed: unknown;
try {
parsed = JSON.parse(read.value);
} catch (cause: unknown) {
return err({
kind: "malformed",
path: settings.userConfigPath,
detail: `Cannot parse Junie's user configuration as JSON to determine its MCP locations: ${errorMessage(cause)}`,
});
}
const record = clientConfigurationRecordSchema.safeParse(parsed);
const value = record.success
? record.data["mcp-default-locations"]
: undefined;
if (record.success && value === undefined) return ok(undefined);
if (typeof value !== "boolean")
return err({
kind: "malformed",
path: settings.userConfigPath,
detail:
"Junie's user configuration does not establish whether default MCP locations are enabled: mcp-default-locations is not a boolean.",
});
return ok(
value
? undefined
: "Junie's user configuration disables its default MCP locations, so Junie does not load this registration.",
);
};