Files
rea/src/config/electronAutomation.ts
T
morlutoandGitHub b8a9da0c0f refactor(mcp): make analysis states unrepresentable (#468)
* refactor(config): parse capability settings into exact states

* refactor(runtime): encode replay and process outcomes exactly

* refactor: make analysis states unrepresentable

* refactor(mcp): register canonical schemas with SDK

* fix: preserve capability and catalog invariants

* fix(build): remove stale compiled modules

* fix(replay): update real verifier policy dependency

* fix(package): verify the complete MCP catalog

* fix(test): supply complete replay reload policy

* refactor(contracts): centralize output schema lookup

* refactor(mcp): delegate protocol boundaries to SDK

* fix(browser): approve real source capture

* fix(mcp): preserve catalog guidance
2026-08-10 02:28:11 +08:00

69 lines
2.6 KiB
TypeScript

import type { PermissionCeiling } from "../domain/permissionPolicy.js";
import { ConfigurationError } from "../domain/errors.js";
import { err, ok, type Result } from "../domain/result.js";
import { permissionScope } from "./permissions.js";
import { parseAbsoluteRoots } from "./parsers.js";
import type { Environment } from "./environment.js";
/** Parsed availability and authority scope for active Electron automation. */
export type ElectronAutomationPolicy =
| { readonly status: "disabled" }
| {
readonly status: "enabled";
readonly executableRoots: readonly [string, ...string[]];
readonly applicationRoots: readonly [string, ...string[]];
};
/** Parse active Electron automation into a closed disabled or enabled policy. */
export const parseElectronAutomationPolicy = (
env: Environment,
): Result<ElectronAutomationPolicy, ConfigurationError> => {
const executableRoots = parseAbsoluteRoots(
env.REA_ELECTRON_AUTOMATE_EXECUTABLE_ROOTS_JSON,
"REA_ELECTRON_AUTOMATE_EXECUTABLE_ROOTS_JSON",
);
if (!executableRoots.ok) return executableRoots;
const applicationRoots = parseAbsoluteRoots(
env.REA_ELECTRON_AUTOMATE_APPLICATION_ROOTS_JSON,
"REA_ELECTRON_AUTOMATE_APPLICATION_ROOTS_JSON",
);
if (!applicationRoots.ok) return applicationRoots;
if (env.REA_ELECTRON_AUTOMATE_ENABLED !== "true")
return ok({ status: "disabled" });
const [firstExecutableRoot, ...remainingExecutableRoots] =
executableRoots.value;
if (firstExecutableRoot === undefined)
return err(
new ConfigurationError(
"REA_ELECTRON_AUTOMATE_EXECUTABLE_ROOTS_JSON must encode at least one absolute root when Electron automation is enabled",
),
);
const [firstApplicationRoot, ...remainingApplicationRoots] =
applicationRoots.value;
if (firstApplicationRoot === undefined)
return err(
new ConfigurationError(
"REA_ELECTRON_AUTOMATE_APPLICATION_ROOTS_JSON must encode at least one absolute root when Electron automation is enabled",
),
);
return ok({
status: "enabled",
executableRoots: [firstExecutableRoot, ...remainingExecutableRoots],
applicationRoots: [firstApplicationRoot, ...remainingApplicationRoots],
});
};
/** Add the separately permissioned, no-network Electron automation ceiling. */
export const appendElectronAutomationCeiling = (
ceilings: PermissionCeiling[],
policy: ElectronAutomationPolicy,
): void => {
if (policy.status === "disabled") return;
ceilings.push(
permissionScope("electron_automate", policy.applicationRoots, {
executables: policy.executableRoots,
network: "external",
}),
);
};