feat(application): add isolated JavaScript replay
Expose one plan/execute replay contract through both CLI and MCP with exact source, input, runtime, sandbox, limit, and export commitments. Run selected ESM and extracted CommonJS/Rspack factories in a disposable Linux x64 Bubblewrap namespace with a content-addressed Node ELF closure, architecture-checked seccomp, delegated systemd cgroup limits, bounded protocol capture, cancellation, and observable cleanup. Preserve left and right observations as Evidence, derive differential comparisons without erasing unknowns, add optional separately authorized reproducers, and fail closed on stale plans or unavailable host boundaries. Add source-owned parser, sanitizer, clipboard, denial, timeout, OOM, protocol-forgery, and cancellation coverage; a real Linux verifier and workflow; regenerated catalogs and TypeDoc; and updated the packaged REA analysis skill for the 83-tool inventory.
This commit is contained in:
@@ -20,6 +20,13 @@ import { registerBrowserTools } from "./registerBrowserTools.js";
|
||||
import type { ElectronObservationPort } from "../application/ElectronObservationPort.js";
|
||||
import { registerElectronTools } from "./registerElectronTools.js";
|
||||
import { registerApplicationTools } from "./registerApplicationTools.js";
|
||||
import type {
|
||||
JavaScriptReplayHost,
|
||||
JavaScriptReplayPolicy,
|
||||
JavaScriptReplayRunner,
|
||||
} from "../application/JavaScriptReplayPlanning.js";
|
||||
import { LinuxJavaScriptReplayRunner } from "../replay/LinuxJavaScriptReplayRunner.js";
|
||||
import { SystemJavaScriptReplayHost } from "../replay/SystemJavaScriptReplayHost.js";
|
||||
|
||||
export interface CreateServerOptions {
|
||||
readonly logger?: Logger;
|
||||
@@ -31,11 +38,15 @@ export interface CreateServerOptions {
|
||||
readonly browserObservation?: BrowserObservationPort;
|
||||
readonly electronObservation?: ElectronObservationPort;
|
||||
readonly artifactIntegrityContinueEnabled?: () => boolean;
|
||||
readonly javascriptReplayPolicy?: JavaScriptReplayPolicy;
|
||||
readonly javascriptReplayHost?: JavaScriptReplayHost;
|
||||
readonly javascriptReplayRunner?: JavaScriptReplayRunner;
|
||||
readonly availabilityPolicy?: () => {
|
||||
readonly processCaptureEnabled: boolean;
|
||||
readonly evidenceFileRoots: number;
|
||||
readonly browserObservationEnabled?: boolean;
|
||||
readonly electronObservationEnabled?: boolean;
|
||||
readonly javascriptReplayEnabled?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -174,6 +185,21 @@ export const createServer = (
|
||||
logger: toolLogger,
|
||||
recordEvidence,
|
||||
recordEvidenceWithUnknown,
|
||||
replay: {
|
||||
policy: options.javascriptReplayPolicy ?? {
|
||||
enabled: false,
|
||||
roots: [],
|
||||
nodePath: process.execPath,
|
||||
bubblewrapPath: "/usr/bin/bwrap",
|
||||
systemdRunPath: "/usr/bin/systemd-run",
|
||||
systemctlPath: "/usr/bin/systemctl",
|
||||
shellPath: "/usr/bin/bash",
|
||||
},
|
||||
host: options.javascriptReplayHost ?? new SystemJavaScriptReplayHost(),
|
||||
runner:
|
||||
options.javascriptReplayRunner ?? new LinuxJavaScriptReplayRunner(),
|
||||
authority: options.permissionAuthority,
|
||||
},
|
||||
});
|
||||
registerGuidedPrompts(server, analysis, session);
|
||||
if (session !== undefined) {
|
||||
|
||||
@@ -5,15 +5,24 @@ import {
|
||||
compareApplicationVersionsEvidence,
|
||||
traceApplicationFeatureEvidence,
|
||||
} from "../application/JavaScriptApplicationWorkflowService.js";
|
||||
import {
|
||||
runControlledReplay,
|
||||
type JavaScriptReplayDependencies,
|
||||
} from "../application/JavaScriptReplayService.js";
|
||||
import { APPLICATION_TOOL_CONTRACTS } from "../contracts/applicationToolContracts.js";
|
||||
import { compareApplicationVersionsInputSchema } from "../domain/javascriptApplicationVersionComparisonSchemas.js";
|
||||
import { applicationVersionComparisonResultSchema } from "../domain/javascriptApplicationVersionComparisonSchemas.js";
|
||||
import { traceApplicationFeatureInputSchema } from "../domain/javascriptFeatureTraceSchemas.js";
|
||||
import type { Evidence } from "../domain/evidence.js";
|
||||
import { parseEvidence, type Evidence } from "../domain/evidence.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import {
|
||||
controlledReplayInputSchema,
|
||||
controlledReplayOutputSchema,
|
||||
} from "../domain/javascriptReplay.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { mcpProgressReporter } from "./mcpProgress.js";
|
||||
|
||||
interface ApplicationToolRegistration {
|
||||
readonly logger: Logger;
|
||||
@@ -21,6 +30,7 @@ interface ApplicationToolRegistration {
|
||||
readonly recordEvidenceWithUnknown:
|
||||
| BinarySessionPort["recordEvidenceWithUnknown"]
|
||||
| undefined;
|
||||
readonly replay: JavaScriptReplayDependencies;
|
||||
}
|
||||
|
||||
/** Register provider-neutral JavaScript application graph workflows. */
|
||||
@@ -28,7 +38,8 @@ export const registerApplicationTools = (
|
||||
server: McpServer,
|
||||
options: ApplicationToolRegistration,
|
||||
): void => {
|
||||
const [traceContract, compareContract] = APPLICATION_TOOL_CONTRACTS;
|
||||
const [traceContract, compareContract, replayContract] =
|
||||
APPLICATION_TOOL_CONTRACTS;
|
||||
server.registerTool(
|
||||
traceContract.name,
|
||||
toolRegistrationOptions(traceContract),
|
||||
@@ -77,6 +88,41 @@ export const registerApplicationTools = (
|
||||
);
|
||||
},
|
||||
);
|
||||
server.registerTool(
|
||||
replayContract.name,
|
||||
toolRegistrationOptions(replayContract),
|
||||
async (input, context) => {
|
||||
const parsed = controlledReplayInputSchema.parse(input);
|
||||
const result = await logToolExecution(
|
||||
options.logger,
|
||||
replayContract.name,
|
||||
() =>
|
||||
runControlledReplay(options.replay, parsed, {
|
||||
signal: context.mcpReq.signal,
|
||||
progress: mcpProgressReporter(context),
|
||||
}),
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, replayContract);
|
||||
const output = controlledReplayOutputSchema.parse(result.value);
|
||||
if (output.evidence !== null) {
|
||||
const sourcesRecorded = recordSources(
|
||||
options.recordEvidence,
|
||||
output.source_evidence.map((item) => parseEvidence(item)),
|
||||
);
|
||||
if (!sourcesRecorded.ok)
|
||||
return toCallToolResult(sourcesRecorded, replayContract);
|
||||
const recorded = options.recordEvidence?.(
|
||||
parseEvidence(output.evidence),
|
||||
);
|
||||
if (recorded !== undefined && !recorded.ok)
|
||||
return toCallToolResult(recorded, replayContract);
|
||||
}
|
||||
return toCallToolResult(result, replayContract, {
|
||||
evidenceResourcesAvailable:
|
||||
output.evidence !== null && options.recordEvidence !== undefined,
|
||||
});
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const recordSources = (
|
||||
|
||||
Reference in New Issue
Block a user