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
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import type {
|
||||
EnabledJavaScriptReplayPolicy,
|
||||
JavaScriptReplayPolicy,
|
||||
} from "../application/JavaScriptReplayPlanning.js";
|
||||
import { ConfigurationError } from "../domain/errors.js";
|
||||
import type { PermissionCeiling } from "../domain/permissionPolicy.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import type { Environment } from "./environment.js";
|
||||
import { parseAbsoluteRoots } from "./parsers.js";
|
||||
import { permissionScope } from "./permissions.js";
|
||||
|
||||
/** Parse controlled replay configuration into disabled or fully enabled state. */
|
||||
export const parseJavaScriptReplayPolicy = (
|
||||
env: Environment,
|
||||
): Result<JavaScriptReplayPolicy, ConfigurationError> => {
|
||||
const roots = parseAbsoluteRoots(
|
||||
env.REA_JAVASCRIPT_REPLAY_ROOTS_JSON,
|
||||
"REA_JAVASCRIPT_REPLAY_ROOTS_JSON",
|
||||
);
|
||||
if (!roots.ok) return roots;
|
||||
if (env.REA_JAVASCRIPT_REPLAY_ENABLED !== "true")
|
||||
return ok({ status: "disabled" });
|
||||
const [firstRoot, ...remainingRoots] = roots.value;
|
||||
if (firstRoot === undefined)
|
||||
return err(
|
||||
new ConfigurationError(
|
||||
"REA_JAVASCRIPT_REPLAY_ROOTS_JSON must encode at least one absolute root when JavaScript replay is enabled",
|
||||
),
|
||||
);
|
||||
return ok({
|
||||
status: "enabled",
|
||||
roots: [firstRoot, ...remainingRoots],
|
||||
nodePath: env.REA_JAVASCRIPT_REPLAY_NODE_PATH,
|
||||
bubblewrapPath: env.REA_JAVASCRIPT_REPLAY_BWRAP_PATH,
|
||||
systemdRunPath: env.REA_JAVASCRIPT_REPLAY_SYSTEMD_RUN_PATH,
|
||||
systemctlPath: env.REA_JAVASCRIPT_REPLAY_SYSTEMCTL_PATH,
|
||||
shellPath: env.REA_JAVASCRIPT_REPLAY_SHELL_PATH,
|
||||
});
|
||||
};
|
||||
|
||||
/** Add the exact controlled replay ceiling when replay is enabled. */
|
||||
export const appendJavaScriptReplayCeiling = (
|
||||
ceilings: PermissionCeiling[],
|
||||
policy: JavaScriptReplayPolicy,
|
||||
): void => {
|
||||
if (policy.status === "disabled") return;
|
||||
ceilings.push(
|
||||
permissionScope("javascript_replay", policy.roots, {
|
||||
executables: replayExecutables(policy),
|
||||
network: "none",
|
||||
mount: true,
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
const replayExecutables = (
|
||||
policy: EnabledJavaScriptReplayPolicy,
|
||||
): readonly string[] => [
|
||||
policy.nodePath,
|
||||
policy.bubblewrapPath,
|
||||
policy.systemdRunPath,
|
||||
policy.systemctlPath,
|
||||
policy.shellPath,
|
||||
];
|
||||
Reference in New Issue
Block a user