rea-agents 1.7.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +112 -59
- package/bridge/ghidra/ReaGhidraBridge.java +96 -11
- package/dist/application/ArtifactExtraction.js +1 -1
- package/dist/application/ArtifactInventory/classify.js +42 -0
- package/dist/application/ArtifactInventory/hash.js +43 -0
- package/dist/application/ArtifactInventory/reader.js +41 -0
- package/dist/application/ArtifactInventory/scanCanonical.js +155 -0
- package/dist/application/ArtifactInventory/scanReader.js +124 -0
- package/dist/application/ArtifactInventory/types.js +10 -0
- package/dist/application/ArtifactInventory.js +9 -351
- package/dist/application/AuthorizedArtifactInventory.js +2 -2
- package/dist/application/BinarySession.js +47 -270
- package/dist/application/BinarySessionExecution.js +28 -0
- package/dist/application/BinarySessionOpen.js +39 -0
- package/dist/application/BinarySessionRecords.js +149 -0
- package/dist/application/BinarySessionStatus.js +75 -0
- package/dist/application/CapabilityInventory.js +42 -2
- package/dist/application/ClientRegistrationStatus.js +1 -1
- package/dist/application/CrossVersionInventory.js +8 -2
- package/dist/application/CrossVersionInvestigation.js +11 -29
- package/dist/application/CrossVersionInvestigationCollections.js +23 -0
- package/dist/application/DirectAnalysis.js +47 -44
- package/dist/application/Doctor.js +165 -197
- package/dist/application/DoctorDiagnostics.js +180 -0
- package/dist/application/ElectronBoundaryAnalysis.js +112 -0
- package/dist/application/ElectronBoundaryGraph.js +9 -0
- package/dist/application/ElectronBoundaryGraphContext.js +62 -0
- package/dist/application/ElectronBoundaryGraphIpc.js +242 -0
- package/dist/application/ElectronBoundaryGraphNative.js +86 -0
- package/dist/application/ElectronBoundaryGraphWindows.js +223 -0
- package/dist/application/EnhancedToolPagination.js +22 -0
- package/dist/application/EnhancedToolTypes.js +4 -0
- package/dist/application/EnhancedTools.js +58 -50
- package/dist/application/InstrumentedJavaScriptReplayHost.js +36 -0
- package/dist/application/InvestigationProviders.js +30 -0
- package/dist/application/InvestigationWorkspaceStore.js +24 -10
- package/dist/application/JavaScriptApplicationEvidence.js +26 -0
- package/dist/application/JavaScriptApplicationEvidenceGraph.js +89 -0
- package/dist/application/JavaScriptApplicationService.js +74 -0
- package/dist/application/JavaScriptApplicationWorkflowEvidence.js +29 -0
- package/dist/application/JavaScriptApplicationWorkflowService.js +90 -0
- package/dist/application/JavaScriptArtifactAnalysis.js +52 -7
- package/dist/application/JavaScriptArtifactFiles.js +6 -2
- package/dist/application/JavaScriptArtifactGraphBuilder.js +82 -17
- package/dist/application/JavaScriptArtifactGraphBundlers.js +225 -0
- package/dist/application/JavaScriptArtifactGraphContext.js +37 -36
- package/dist/application/JavaScriptArtifactGraphDocuments.js +27 -4
- package/dist/application/JavaScriptArtifactGraphEvidence.js +24 -14
- package/dist/application/JavaScriptArtifactGraphFindings.js +54 -8
- package/dist/application/JavaScriptArtifactGraphStructure.js +29 -101
- package/dist/application/JavaScriptArtifactPathResolution.js +269 -0
- package/dist/application/JavaScriptArtifactReconstruction.js +4 -1
- package/dist/application/JavaScriptArtifactReconstructionInput.js +2 -83
- package/dist/application/JavaScriptJsonModules.js +39 -0
- package/dist/application/JavaScriptModuleRelationships.js +262 -0
- package/dist/application/JavaScriptReplayPermission.js +16 -0
- package/dist/application/JavaScriptReplayPlanning.js +201 -0
- package/dist/application/JavaScriptReplayService.js +292 -0
- package/dist/application/JavaScriptRuntimeReconciliationEvidence.js +25 -0
- package/dist/application/JavaScriptRuntimeReconciliationService.js +27 -0
- package/dist/application/LinuxHopper.js +10 -0
- package/dist/application/MacHopper.js +22 -11
- package/dist/application/ManagedApplicationGraphService.js +55 -0
- package/dist/application/ManagedMemberComparisonService.js +122 -0
- package/dist/application/ManagedNativeVerificationService.js +39 -0
- package/dist/application/ManagedReconstructionService.js +58 -0
- package/dist/application/ManagedRuntimeCorrelationService.js +103 -0
- package/dist/application/NodeRuntimeCharacterizationService.js +196 -0
- package/dist/application/PermissionAuthority.js +106 -63
- package/dist/application/ProcessCaptureCapability.js +1 -1
- package/dist/application/ProcessCapturePermission.js +13 -0
- package/dist/application/ProcessCli.js +2 -12
- package/dist/application/ProcessHarness.js +1 -1
- package/dist/application/ProcessSampling.js +15 -11
- package/dist/application/ProjectPermissionStore.js +49 -9
- package/dist/application/RealHopperAssertions.js +76 -0
- package/dist/application/ReconstructionCoverageService.js +69 -0
- package/dist/application/ReconstructionCoverageWorkspaceStore.js +31 -0
- package/dist/application/RuntimeExecutableDiagnostics.js +172 -0
- package/dist/application/Setup.js +147 -259
- package/dist/application/SetupClientConfiguration.js +220 -0
- package/dist/application/SetupClients.js +24 -2
- package/dist/application/SetupPlan.js +123 -12
- package/dist/application/SetupSkill.js +26 -12
- package/dist/application/SupportedClients.js +1 -0
- package/dist/application/Uninstall.js +6 -3
- package/dist/application/WindowsCapabilities.js +86 -0
- package/dist/application/runtime.js +2 -0
- package/dist/artifacts/AsarArtifactReader.js +11 -0
- package/dist/browser/BrowserProcessStartup.js +88 -0
- package/dist/browser/CdpCaptureDocuments.js +12 -8
- package/dist/browser/CdpCaptureEventBodyShapes.js +75 -0
- package/dist/browser/CdpCaptureEventHandlers.js +336 -0
- package/dist/browser/CdpCaptureEventHelpers.js +71 -0
- package/dist/browser/CdpCaptureEventState.js +1 -0
- package/dist/browser/CdpCaptureEventTypes.js +1 -0
- package/dist/browser/CdpCaptureEvents.js +46 -464
- package/dist/browser/CdpElectronInspection.js +106 -162
- package/dist/browser/CdpElectronProvider.js +5 -1
- package/dist/browser/CdpElectronScriptEvents.js +69 -0
- package/dist/browser/CdpElectronScripts.js +94 -0
- package/dist/browser/CdpElectronWorkers.js +56 -0
- package/dist/browser/CdpObservationSession.js +51 -8
- package/dist/browser/CdpPageCapture.js +12 -129
- package/dist/browser/CdpPageCaptureScripts.js +97 -0
- package/dist/browser/CdpPageCaptureWorkers.js +46 -0
- package/dist/browser/CdpWebMcpDiscovery.js +38 -14
- package/dist/browser/PngVisualDiff.js +9 -2
- package/dist/catalogIdentity.js +8 -1
- package/dist/cli/artifactCommands.js +82 -0
- package/dist/cli/coreAnalysisCommands.js +232 -0
- package/dist/cli/managedCommands.js +397 -0
- package/dist/cli/managedProjectGraphCommand.js +24 -0
- package/dist/cli/options.js +9 -0
- package/dist/cli/setupCommands.js +108 -0
- package/dist/cli/types.js +1 -0
- package/dist/cli/utilityCommands.js +122 -0
- package/dist/cli.js +13 -383
- package/dist/cliApplicationCommands.js +176 -0
- package/dist/cliBrowserAdvancedCommands.js +73 -16
- package/dist/cliBrowserCommands.js +39 -115
- package/dist/cliCommandNames.js +17 -0
- package/dist/cliElectronCommands.js +100 -27
- package/dist/cliEvidenceCommands.js +13 -2
- package/dist/cliInvestigationCommands.js +53 -10
- package/dist/cliJsonInput.js +54 -0
- package/dist/cliObservationOptions.js +137 -0
- package/dist/cliPolicyCommands.js +80 -46
- package/dist/cliSetup.js +289 -0
- package/dist/config/environment.js +107 -0
- package/dist/config/parseConfig.js +228 -0
- package/dist/config/parsers.js +68 -0
- package/dist/config/permissions.js +30 -0
- package/dist/config/types.js +1 -0
- package/dist/config.js +1 -292
- package/dist/contracts/applicationToolContracts.js +225 -0
- package/dist/contracts/artifactToolContracts.js +5 -9
- package/dist/contracts/browserToolContracts.js +14 -62
- package/dist/contracts/electronToolContracts.js +45 -19
- package/dist/contracts/errorSchemas.js +1 -0
- package/dist/contracts/investigationExamples.js +0 -6
- package/dist/contracts/javascriptApplicationWorkflowExamples.js +46 -0
- package/dist/contracts/javascriptRuntimeReconciliationExample.js +208 -0
- package/dist/contracts/managedToolContracts.js +153 -0
- package/dist/contracts/managedWorkflowExamples.js +346 -0
- package/dist/contracts/managedWorkflowToolContracts.js +203 -0
- package/dist/contracts/nativeToolContracts.js +2 -6
- package/dist/contracts/promptContracts.js +18 -2
- package/dist/contracts/providerSelection.js +2 -0
- package/dist/contracts/toolContractExamples.js +10 -25
- package/dist/contracts/toolContracts.js +49 -47
- package/dist/contracts/toolEffects.js +174 -0
- package/dist/contracts/toolOutputSchemaGroups.js +232 -0
- package/dist/contracts/toolOutputSchemaPrimitives.js +327 -0
- package/dist/contracts/toolOutputSchemas.js +2 -535
- package/dist/doctorRuntime.js +42 -1
- package/dist/domain/analysisErrorPresentation.js +234 -0
- package/dist/domain/analysisErrorProjection.js +284 -0
- package/dist/domain/artifactComparison.js +37 -19
- package/dist/domain/binaryTarget.js +87 -37
- package/dist/domain/browserObservation.js +1 -282
- package/dist/domain/browserObservationSchemas.js +286 -0
- package/dist/domain/bundleComparison.js +4 -4
- package/dist/domain/electronObservation.js +13 -0
- package/dist/domain/electronStaticAnalysis.js +9 -0
- package/dist/domain/electronStaticAnalysisBrowser.js +206 -0
- package/dist/domain/electronStaticAnalysisIpc.js +171 -0
- package/dist/domain/electronStaticAnalysisNative.js +164 -0
- package/dist/domain/electronStaticAnalysisTypes.js +1 -0
- package/dist/domain/electronStaticAnalysisValues.js +103 -0
- package/dist/domain/errors.js +32 -448
- package/dist/domain/functionComparison.js +4 -165
- package/dist/domain/functionComparisonDimensions.js +164 -0
- package/dist/domain/functionComparisonSchemas.js +3 -8
- package/dist/domain/inputIssueProjection.js +52 -0
- package/dist/domain/javascriptApplicationAnalysis.js +155 -0
- package/dist/domain/javascriptApplicationChangeGraph.js +231 -0
- package/dist/domain/javascriptApplicationEvidenceSchemas.js +18 -0
- package/dist/domain/javascriptApplicationGraph.js +2 -1
- package/dist/domain/javascriptApplicationGraphSchemas.js +7 -0
- package/dist/domain/javascriptApplicationVersionComparison.js +116 -0
- package/dist/domain/javascriptApplicationVersionComparisonSchemas.js +139 -0
- package/dist/domain/javascriptApplicationVersionItems.js +233 -0
- package/dist/domain/javascriptApplicationVersionKeys.js +170 -0
- package/dist/domain/javascriptExportInstrumentation.js +97 -0
- package/dist/domain/javascriptFeatureSeed.js +140 -0
- package/dist/domain/javascriptFeatureTrace.js +232 -0
- package/dist/domain/javascriptFeatureTraceSchemas.js +136 -0
- package/dist/domain/javascriptFeatureTraversal.js +100 -0
- package/dist/domain/javascriptNativeHandoff.js +85 -0
- package/dist/domain/javascriptReplay.js +361 -0
- package/dist/domain/javascriptRuntimeLoadState.js +106 -0
- package/dist/domain/javascriptRuntimeReconciliation.js +42 -0
- package/dist/domain/javascriptRuntimeReconciliationGraph.js +169 -0
- package/dist/domain/javascriptRuntimeReconciliationMatching.js +247 -0
- package/dist/domain/javascriptRuntimeReconciliationParsing.js +160 -0
- package/dist/domain/javascriptRuntimeReconciliationResult.js +119 -0
- package/dist/domain/javascriptRuntimeReconciliationRuntime.js +316 -0
- package/dist/domain/javascriptRuntimeReconciliationSchemas.js +245 -0
- package/dist/domain/javascriptRuntimeStaticCandidates.js +193 -0
- package/dist/domain/javascriptSemanticAnalysis.js +386 -0
- package/dist/domain/javascriptSemanticIr.js +30 -0
- package/dist/domain/javascriptSemanticProjection.js +366 -0
- package/dist/domain/javascriptSemanticState.js +40 -0
- package/dist/domain/javascriptSemanticTraversal.js +22 -0
- package/dist/domain/javascriptSemanticValues.js +352 -0
- package/dist/domain/javascriptStaticAnalysis.js +26 -254
- package/dist/domain/javascriptStaticAnalysisBundler.js +209 -0
- package/dist/domain/javascriptStaticAnalysisCalls.js +180 -0
- package/dist/domain/javascriptStaticAnalysisFindings.js +39 -0
- package/dist/domain/javascriptStaticAnalysisHelpers.js +81 -2
- package/dist/domain/javascriptStaticAnalysisState.js +6 -0
- package/dist/domain/knownPageCoverage.js +21 -0
- package/dist/domain/managedApplicationGraph.js +206 -0
- package/dist/domain/managedApplicationGraphCoverage.js +170 -0
- package/dist/domain/managedApplicationGraphNodeCoverage.js +6 -0
- package/dist/domain/managedApplicationGraphNodes.js +336 -0
- package/dist/domain/managedArtifact.js +452 -0
- package/dist/domain/managedMemberComparison.js +211 -0
- package/dist/domain/managedMemberComparisonCoverage.js +72 -0
- package/dist/domain/managedMemberComparisonMatch.js +356 -0
- package/dist/domain/managedNativeVerification.js +46 -0
- package/dist/domain/managedNativeVerificationMatch.js +272 -0
- package/dist/domain/managedNativeVerificationSchemas.js +141 -0
- package/dist/domain/managedReconstruction.js +196 -0
- package/dist/domain/managedRuntimeCorrelation.js +184 -0
- package/dist/domain/nodeRuntimeCharacterization.js +66 -0
- package/dist/domain/permissionPolicy.js +2 -0
- package/dist/domain/reconstructionCoverage.js +387 -0
- package/dist/domain/reconstructionCoverageEvaluation.js +212 -0
- package/dist/domain/reconstructionVerificationSchemas.js +9 -3
- package/dist/domain/runtimeCharacterization.js +85 -0
- package/dist/domain/webBundleAnalyzer.js +3 -409
- package/dist/domain/webBundleAnalyzerAst.js +77 -0
- package/dist/domain/webBundleAnalyzerInspection.js +307 -0
- package/dist/domain/webBundleAnalyzerResult.js +120 -0
- package/dist/dotnet/ManagedArtifactInspector.js +339 -0
- package/dist/dotnet/ManagedMemberInspector.js +153 -0
- package/dist/dotnet/ManagedMemberInspectorCore.js +297 -0
- package/dist/dotnet/ManagedMemberInstructionDecoder.js +427 -0
- package/dist/dotnet/ManagedMemberRows.js +120 -0
- package/dist/dotnet/ManagedMetadataHeaps.js +131 -0
- package/dist/dotnet/ManagedMetadataInventory.js +104 -0
- package/dist/dotnet/ManagedMetadataInventoryRows.js +292 -0
- package/dist/dotnet/ManagedMetadataLayout.js +259 -0
- package/dist/dotnet/ManagedMetadataRowSizes.js +54 -0
- package/dist/dotnet/ManagedMethodBodyReader.js +143 -0
- package/dist/dotnet/ManagedNativeBoundaryHelpers.js +311 -0
- package/dist/dotnet/ManagedNativeBoundaryInspector.js +143 -0
- package/dist/dotnet/ManagedPeReader.js +188 -0
- package/dist/dotnet/ManagedReaderFailure.js +10 -0
- package/dist/dotnet/ManagedStaticProvider.js +203 -0
- package/dist/generatedPackageMetadata.js +2 -2
- package/dist/ghidra/GhidraClient.js +76 -91
- package/dist/ghidra/GhidraClientStartup.js +29 -0
- package/dist/ghidra/GhidraClientWire.js +34 -0
- package/dist/ghidra/GhidraDefaults.js +1 -1
- package/dist/ghidra/GhidraDiagnostics.js +6 -1
- package/dist/ghidra/GhidraInstallation.js +20 -15
- package/dist/ghidra/GhidraLauncher.js +93 -29
- package/dist/ghidra/GhidraProvider.js +67 -161
- package/dist/ghidra/GhidraProviderCapabilities.js +173 -0
- package/dist/ghidra/GhidraSessionValues.js +2 -0
- package/dist/ghidra/GhidraSocketConnection.js +44 -7
- package/dist/ghidra/GhidraTargetSnapshot.js +30 -0
- package/dist/ghidra/GhidraTransport.js +71 -0
- package/dist/identity.js +3 -2
- package/dist/main/messages.js +5 -0
- package/dist/main/reload.js +49 -0
- package/dist/main/shutdown.js +25 -0
- package/dist/main/startup.js +14 -0
- package/dist/main/state.js +26 -0
- package/dist/main/transport.js +61 -0
- package/dist/main/types.js +1 -0
- package/dist/main.js +35 -132
- package/dist/process/PrivateRuntimeRoot.js +3 -2
- package/dist/process/ProcessOwnership.js +35 -0
- package/dist/process/ProviderProcess.js +2 -0
- package/dist/replay/JavaScriptReplayWorker.js +300 -0
- package/dist/replay/LinuxJavaScriptReplayRunner.js +217 -0
- package/dist/replay/LinuxJavaScriptReplaySandbox.js +140 -0
- package/dist/replay/LinuxRuntimeClosure.js +46 -0
- package/dist/replay/LinuxSeccompPolicy.js +40 -0
- package/dist/replay/ReplayOutcome.js +95 -0
- package/dist/replay/ReplayProcessLifecycle.js +71 -0
- package/dist/replay/ReplayWorkerProtocol.js +55 -0
- package/dist/replay/SystemJavaScriptReplayHost.js +182 -0
- package/dist/server/ProcessCaptureElicitation.js +157 -0
- package/dist/server/createServer.js +158 -41
- package/dist/server/registerApplicationTools/characterization.js +57 -0
- package/dist/server/registerApplicationTools/compareVersions.js +34 -0
- package/dist/server/registerApplicationTools/controlledReplay.js +38 -0
- package/dist/server/registerApplicationTools/coverage.js +84 -0
- package/dist/server/registerApplicationTools/helpers.js +42 -0
- package/dist/server/registerApplicationTools/traceFeature.js +26 -0
- package/dist/server/registerApplicationTools/types.js +1 -0
- package/dist/server/registerApplicationTools.js +13 -0
- package/dist/server/registerArtifactComparisonTool.js +16 -9
- package/dist/server/registerBrowserTools.js +61 -60
- package/dist/server/registerBundleComparisonTool.js +17 -20
- package/dist/server/registerElectronTools.js +39 -12
- package/dist/server/registerEnhancedTools.js +52 -15
- package/dist/server/registerEvidenceResources.js +54 -0
- package/dist/server/registerEvidenceTools.js +5 -1
- package/dist/server/registerFunctionComparisonTool.js +14 -7
- package/dist/server/registerInvestigationTools/helpers.js +74 -0
- package/dist/server/registerInvestigationTools/types.js +1 -0
- package/dist/server/registerInvestigationTools.js +103 -132
- package/dist/server/registerManagedTools.js +6 -0
- package/dist/server/registerManagedWorkflowTools/compareManagedMembers.js +65 -0
- package/dist/server/registerManagedWorkflowTools/contract.js +8 -0
- package/dist/server/registerManagedWorkflowTools/evidence.js +43 -0
- package/dist/server/registerManagedWorkflowTools/importManagedReconstruction.js +39 -0
- package/dist/server/registerManagedWorkflowTools/planManagedRuntimeCorrelation.js +39 -0
- package/dist/server/registerManagedWorkflowTools/projectManagedApplicationGraph.js +52 -0
- package/dist/server/registerManagedWorkflowTools/types.js +1 -0
- package/dist/server/registerManagedWorkflowTools/verifyManagedNativeBoundaries.js +75 -0
- package/dist/server/registerManagedWorkflowTools.js +13 -0
- package/dist/server/registerOfficialTools.js +81 -67
- package/dist/server/registerProcessComparisonTool.js +25 -47
- package/dist/server/registerSessionRecordTools.js +137 -0
- package/dist/server/registerSessionStatusTool.js +9 -8
- package/dist/server/registerSessionTools.js +77 -216
- package/dist/server/sessionAvailabilityPolicy.js +10 -0
- package/dist/server/sessionEvidence.js +14 -19
- package/dist/server/toolInputValidation.js +77 -0
- package/dist/server/toolRegistrationOptions.js +177 -2
- package/dist/server/toolResult.js +30 -17
- package/package.json +21 -14
- package/scripts/rea.mjs +1 -1
- package/skills/{rea-analysis → reverse-engineer-anything}/SKILL.md +75 -6
- package/scripts/prepare-node-pty.mjs +0 -35
- package/scripts/rebuild-native.mjs +0 -22
package/dist/main.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
3
|
import { realpathSync } from "node:fs";
|
|
4
|
-
import { serveStdio
|
|
4
|
+
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
5
5
|
import { parseConfig } from "./config.js";
|
|
6
6
|
import { createBinarySession } from "./application/runtime.js";
|
|
7
|
-
import { createServer } from "./server/createServer.js";
|
|
8
7
|
import { createLogger } from "./logger.js";
|
|
9
8
|
import { projectAnalysisError } from "./domain/errors.js";
|
|
10
|
-
import { readProjectPermissionStore } from "./application/ProjectPermissionStore.js";
|
|
11
9
|
import { loadConfiguredPermissionAuthority } from "./application/PermissionConfiguration.js";
|
|
12
10
|
import { CdpBrowserProvider } from "./browser/CdpBrowserProvider.js";
|
|
13
11
|
import { CdpElectronProvider } from "./browser/CdpElectronProvider.js";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
import { SERVER_START_FAILED } from "./main/messages.js";
|
|
13
|
+
import { createRuntimeState } from "./main/state.js";
|
|
14
|
+
import { openInitialTarget } from "./main/startup.js";
|
|
15
|
+
import { startMcpTransport } from "./main/transport.js";
|
|
16
|
+
import { registerConfigReload } from "./main/reload.js";
|
|
17
|
+
import { createShutdown } from "./main/shutdown.js";
|
|
18
18
|
const runtimeDependencies = () => ({
|
|
19
19
|
env: process.env,
|
|
20
20
|
serve: serveStdio,
|
|
@@ -60,132 +60,35 @@ export const run = async (dependencies = runtimeDependencies()) => {
|
|
|
60
60
|
const session = createBinarySession(config.value, logger);
|
|
61
61
|
const browserObservation = new CdpBrowserProvider();
|
|
62
62
|
const electronObservation = new CdpElectronProvider();
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
...config.value.processExecutionPolicy,
|
|
77
|
-
executableRoots: [...config.value.processExecutionPolicy.executableRoots],
|
|
78
|
-
workingRoots: [...config.value.processExecutionPolicy.workingRoots],
|
|
79
|
-
allowedEnvironment: [
|
|
80
|
-
...config.value.processExecutionPolicy.allowedEnvironment,
|
|
81
|
-
],
|
|
82
|
-
};
|
|
83
|
-
const runtimeEvidencePolicy = {
|
|
84
|
-
...config.value.evidenceFilePolicy,
|
|
85
|
-
roots: [...config.value.evidenceFilePolicy.roots],
|
|
86
|
-
};
|
|
87
|
-
const runtimeSnapshotPolicy = {
|
|
88
|
-
...config.value.analysisSnapshotFilePolicy,
|
|
89
|
-
roots: [...config.value.analysisSnapshotFilePolicy.roots],
|
|
90
|
-
};
|
|
91
|
-
const runtimeInvestigationRoots = [...config.value.investigationInputRoots];
|
|
92
|
-
const liveServers = new Set();
|
|
93
|
-
let handle;
|
|
94
|
-
try {
|
|
95
|
-
handle = dependencies.serve(() => {
|
|
96
|
-
const server = (dependencies.createServer ?? createServer)(session, session, {
|
|
97
|
-
logger,
|
|
98
|
-
processPolicy: runtimeProcessPolicy,
|
|
99
|
-
evidenceFilePolicy: runtimeEvidencePolicy,
|
|
100
|
-
investigationInputRoots: runtimeInvestigationRoots,
|
|
101
|
-
analysisSnapshotFilePolicy: runtimeSnapshotPolicy,
|
|
102
|
-
permissionAuthority: permissionAuthority.value,
|
|
103
|
-
browserObservation,
|
|
104
|
-
electronObservation,
|
|
105
|
-
artifactIntegrityContinueEnabled: () => currentConfig.artifactIntegrityContinueEnabled,
|
|
106
|
-
availabilityPolicy: () => ({
|
|
107
|
-
processCaptureEnabled: currentConfig.processExecutionPolicy.enabled,
|
|
108
|
-
evidenceFileRoots: currentConfig.evidenceFilePolicy.roots.length,
|
|
109
|
-
browserObservationEnabled: currentConfig.browserObservationEnabled &&
|
|
110
|
-
currentConfig.browserCdpEndpoints.length > 0 &&
|
|
111
|
-
currentConfig.browserAllowedOrigins.length > 0,
|
|
112
|
-
electronObservationEnabled: currentConfig.electronObservationEnabled &&
|
|
113
|
-
currentConfig.electronCdpEndpoints.length > 0 &&
|
|
114
|
-
currentConfig.electronFileRoots.length > 0,
|
|
115
|
-
}),
|
|
116
|
-
});
|
|
117
|
-
liveServers.add(server);
|
|
118
|
-
return server;
|
|
119
|
-
}, {
|
|
120
|
-
onerror: () => {
|
|
121
|
-
serverLogger.error(MCP_CONNECTION_LOST);
|
|
122
|
-
dependencies.writeStderr(`${MCP_CONNECTION_LOST}\n`);
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
catch {
|
|
127
|
-
await session.close();
|
|
128
|
-
serverLogger.error(MCP_CONNECTION_START_FAILED);
|
|
129
|
-
dependencies.writeStderr(`${MCP_CONNECTION_START_FAILED}\n`);
|
|
63
|
+
const opened = await openInitialTarget(session, config.value, serverLogger, dependencies.writeStderr);
|
|
64
|
+
if (!opened.ok)
|
|
65
|
+
return opened.exitCode;
|
|
66
|
+
const runtimeState = createRuntimeState(config.value);
|
|
67
|
+
const transport = await startMcpTransport(dependencies, session, {
|
|
68
|
+
logger,
|
|
69
|
+
serverLogger,
|
|
70
|
+
browserObservation,
|
|
71
|
+
electronObservation,
|
|
72
|
+
permissionAuthority: permissionAuthority.value,
|
|
73
|
+
runtimeState,
|
|
74
|
+
});
|
|
75
|
+
if (!transport.ok)
|
|
130
76
|
return 1;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
serverLogger.error("Reloaded project grants could not be read");
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
projectGrants = project.value?.grants ?? [];
|
|
150
|
-
}
|
|
151
|
-
const reloaded = await permissionAuthority.value.replaceConfiguredPolicy({
|
|
152
|
-
ceilings: refreshed.value.permissionCeilings,
|
|
153
|
-
administratorGrants: refreshed.value.administratorPermissionGrants,
|
|
154
|
-
projectGrants,
|
|
155
|
-
});
|
|
156
|
-
if (!reloaded.ok) {
|
|
157
|
-
serverLogger.error("Reloaded permission policy could not be applied");
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
currentConfig = refreshed.value;
|
|
161
|
-
Object.assign(runtimeProcessPolicy, refreshed.value.processExecutionPolicy);
|
|
162
|
-
Object.assign(runtimeEvidencePolicy, refreshed.value.evidenceFilePolicy);
|
|
163
|
-
Object.assign(runtimeSnapshotPolicy, refreshed.value.analysisSnapshotFilePolicy);
|
|
164
|
-
runtimeInvestigationRoots.splice(0, runtimeInvestigationRoots.length, ...refreshed.value.investigationInputRoots);
|
|
165
|
-
for (const server of liveServers)
|
|
166
|
-
server.sendToolListChanged();
|
|
167
|
-
});
|
|
168
|
-
}) ?? (() => undefined);
|
|
169
|
-
let shutdownPromise;
|
|
170
|
-
let unregisterShutdown = () => undefined;
|
|
171
|
-
const shutdown = () => {
|
|
172
|
-
shutdownPromise ??= (async () => {
|
|
173
|
-
unregisterReload();
|
|
174
|
-
unregisterShutdown();
|
|
175
|
-
await handle.close();
|
|
176
|
-
await session.close();
|
|
177
|
-
permissionAuthority.value.clearSessionGrants();
|
|
178
|
-
})();
|
|
179
|
-
return shutdownPromise;
|
|
180
|
-
};
|
|
181
|
-
const requestShutdown = () => {
|
|
182
|
-
shutdown().catch(() => {
|
|
183
|
-
dependencies.setExitCode(1);
|
|
184
|
-
serverLogger.error(MCP_SHUTDOWN_FAILED);
|
|
185
|
-
dependencies.writeStderr(`${MCP_SHUTDOWN_FAILED}\n`);
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
unregisterShutdown = dependencies.registerShutdown(requestShutdown);
|
|
77
|
+
const unregisterReload = registerConfigReload({
|
|
78
|
+
dependencies,
|
|
79
|
+
permissionAuthority: permissionAuthority.value,
|
|
80
|
+
runtimeState,
|
|
81
|
+
liveServers: transport.liveServers,
|
|
82
|
+
serverLogger,
|
|
83
|
+
});
|
|
84
|
+
createShutdown({
|
|
85
|
+
handle: transport.handle,
|
|
86
|
+
session,
|
|
87
|
+
permissionAuthority: permissionAuthority.value,
|
|
88
|
+
unregisterReload,
|
|
89
|
+
dependencies,
|
|
90
|
+
serverLogger,
|
|
91
|
+
});
|
|
189
92
|
return 0;
|
|
190
93
|
};
|
|
191
94
|
/** Run the executable boundary without exposing an unexpected startup cause. */
|
|
@@ -2,10 +2,11 @@ import { chmod, mkdtemp, rm } from "node:fs/promises";
|
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
/**
|
|
5
|
-
* Owns one mode-0700 temporary runtime root and removes it idempotently.
|
|
5
|
+
* Owns one POSIX mode-0700 temporary runtime root and removes it idempotently.
|
|
6
6
|
*
|
|
7
7
|
* Protocol adapters decide what belongs inside the directory; this primitive
|
|
8
|
-
*
|
|
8
|
+
* establishes a private filesystem boundary on POSIX and deterministic cleanup.
|
|
9
|
+
* Windows privacy requires the separately verified native DACL boundary.
|
|
9
10
|
*/
|
|
10
11
|
export class PrivateRuntimeRoot {
|
|
11
12
|
path;
|
|
@@ -2,6 +2,26 @@ import { execFile } from "node:child_process";
|
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import { promisify } from "node:util";
|
|
4
4
|
const execFileAsync = promisify(execFile);
|
|
5
|
+
/**
|
|
6
|
+
* Terminate one Windows process tree through the platform utility.
|
|
7
|
+
*
|
|
8
|
+
* This is a bounded P0 cleanup mechanism, not Job Object ownership proof. The
|
|
9
|
+
* caller-visible Windows limitations must preserve that distinction.
|
|
10
|
+
*/
|
|
11
|
+
export const cleanupWindowsProcessTree = async (rootPid, host = systemWindowsProcessTreeHost) => {
|
|
12
|
+
if (!Number.isSafeInteger(rootPid) || rootPid <= 0)
|
|
13
|
+
return { cleaned: false, reason: "Windows process-tree PID is invalid" };
|
|
14
|
+
try {
|
|
15
|
+
const result = await host.terminateTree(rootPid);
|
|
16
|
+
return { cleaned: true, signaled: result === "terminated" };
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return {
|
|
20
|
+
cleaned: false,
|
|
21
|
+
reason: "Windows P0 process-tree termination failed; Job Object ownership is unavailable",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
};
|
|
5
25
|
/** Select the PTY root group and groups led by an observed captured process. */
|
|
6
26
|
export const selectCapturedProcessGroupIds = (rootPid, samples) => {
|
|
7
27
|
const processGroupIds = new Set([rootPid]);
|
|
@@ -58,6 +78,21 @@ const systemHost = {
|
|
|
58
78
|
process.kill(-processGroupId, signal);
|
|
59
79
|
},
|
|
60
80
|
};
|
|
81
|
+
const systemWindowsProcessTreeHost = {
|
|
82
|
+
async terminateTree(rootPid) {
|
|
83
|
+
try {
|
|
84
|
+
await execFileAsync("taskkill.exe", ["/pid", String(rootPid), "/t", "/f"], { windowsHide: true, timeout: 5_000 });
|
|
85
|
+
return "terminated";
|
|
86
|
+
}
|
|
87
|
+
catch (cause) {
|
|
88
|
+
if (cause instanceof Error &&
|
|
89
|
+
"code" in cause &&
|
|
90
|
+
(cause.code === 128 || cause.code === "ESRCH"))
|
|
91
|
+
return "missing";
|
|
92
|
+
throw cause;
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
};
|
|
61
96
|
/** Read the capture run token currently exposed by one live process. */
|
|
62
97
|
export const readProcessRunId = async (pid, host = systemHost) => (await host.environment(pid)).REA_PROCESS_RUN_ID;
|
|
63
98
|
/**
|
|
@@ -11,8 +11,10 @@ const DEFAULT_KILL_GRACE_MS = 1_000;
|
|
|
11
11
|
export const spawnOwnedProviderProcess = async (options) => {
|
|
12
12
|
const child = spawn(options.command, [...options.arguments], {
|
|
13
13
|
shell: false,
|
|
14
|
+
windowsHide: true,
|
|
14
15
|
stdio: ["ignore", "pipe", "pipe"],
|
|
15
16
|
detached: process.platform !== "win32",
|
|
17
|
+
windowsVerbatimArguments: options.windowsVerbatimArguments ?? false,
|
|
16
18
|
env: {
|
|
17
19
|
...process.env,
|
|
18
20
|
...options.env,
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { Script, SourceTextModule, SyntheticModule, createContext, } from "node:vm";
|
|
2
|
+
import { types } from "node:util";
|
|
3
|
+
class ReplayDeniedError extends Error {
|
|
4
|
+
name = "ReplayDeniedError";
|
|
5
|
+
}
|
|
6
|
+
const main = async () => {
|
|
7
|
+
const chunks = [];
|
|
8
|
+
for await (const chunk of process.stdin)
|
|
9
|
+
chunks.push(Buffer.from(chunk));
|
|
10
|
+
const request = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
11
|
+
if (request.schemaVersion !== 1)
|
|
12
|
+
throw new TypeError("Unsupported replay worker protocol");
|
|
13
|
+
const left = [];
|
|
14
|
+
const right = [];
|
|
15
|
+
for (let index = 0; index < request.cases.length; index += 1) {
|
|
16
|
+
const replayCase = request.cases[index];
|
|
17
|
+
if (replayCase === undefined)
|
|
18
|
+
continue;
|
|
19
|
+
left.push(await runCase(request.left, replayCase, request, index));
|
|
20
|
+
if (request.right !== undefined)
|
|
21
|
+
right.push(await runCase(request.right, replayCase, request, index));
|
|
22
|
+
}
|
|
23
|
+
process.stdout.write(JSON.stringify({
|
|
24
|
+
schema_version: 1,
|
|
25
|
+
left,
|
|
26
|
+
...(request.right === undefined ? {} : { right }),
|
|
27
|
+
}));
|
|
28
|
+
};
|
|
29
|
+
const runCase = async (side, replayCase, request, index) => {
|
|
30
|
+
try {
|
|
31
|
+
const loaded = await loadEntry(side, request, index);
|
|
32
|
+
if (typeof loaded !== "function")
|
|
33
|
+
throw new TypeError(`Replay export is not callable: ${side.entryExport}`);
|
|
34
|
+
const returned = await Reflect.apply(loaded, undefined, [
|
|
35
|
+
...replayCase.arguments,
|
|
36
|
+
]);
|
|
37
|
+
try {
|
|
38
|
+
return {
|
|
39
|
+
case_id: replayCase.caseId,
|
|
40
|
+
outcome: "return",
|
|
41
|
+
value: projectValue(returned, request.limits.resultDepth, request.limits.resultNodes),
|
|
42
|
+
input_sha256: replayCase.inputSha256,
|
|
43
|
+
output_sha256: null,
|
|
44
|
+
truncated: false,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
return exceptionOutcome(replayCase, "serialization_error", error, request.limits.exceptionBytes);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
return exceptionOutcome(replayCase, error instanceof ReplayDeniedError ? "denied" : "exception", error, request.limits.exceptionBytes);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const loadEntry = async (side, request, caseIndex) => {
|
|
56
|
+
const modules = new Map(side.modules.map((module) => [module.alias, module]));
|
|
57
|
+
const context = deterministicContext(request, caseIndex);
|
|
58
|
+
const esmCache = new Map();
|
|
59
|
+
const commonJsCache = new Map();
|
|
60
|
+
const loadCommonJs = (alias) => {
|
|
61
|
+
const cached = commonJsCache.get(alias);
|
|
62
|
+
if (cached !== undefined)
|
|
63
|
+
return cached;
|
|
64
|
+
const descriptor = requiredModule(modules, alias);
|
|
65
|
+
if (descriptor.format !== "commonjs-factory")
|
|
66
|
+
throw new TypeError(`Synchronous require cannot load ESM module: ${alias}`);
|
|
67
|
+
const module = { exports: {} };
|
|
68
|
+
commonJsCache.set(alias, module.exports);
|
|
69
|
+
const requireModule = ((specifier) => {
|
|
70
|
+
const dependency = descriptor.dependencies[specifier];
|
|
71
|
+
if (dependency === undefined)
|
|
72
|
+
throw new ReplayDeniedError(`Undeclared require: ${specifier}`);
|
|
73
|
+
return loadCommonJs(dependency);
|
|
74
|
+
});
|
|
75
|
+
installRspackHelpers(requireModule);
|
|
76
|
+
const source = normalizeFactorySource(descriptor.source);
|
|
77
|
+
const factory = new Script(`(${source})`, {
|
|
78
|
+
filename: `/modules/${alias}.js`,
|
|
79
|
+
}).runInContext(context);
|
|
80
|
+
factory(module, module.exports, requireModule);
|
|
81
|
+
commonJsCache.set(alias, module.exports);
|
|
82
|
+
return module.exports;
|
|
83
|
+
};
|
|
84
|
+
const loadEsm = async (alias) => {
|
|
85
|
+
const cached = esmCache.get(alias);
|
|
86
|
+
if (cached !== undefined)
|
|
87
|
+
return cached;
|
|
88
|
+
const descriptor = requiredModule(modules, alias);
|
|
89
|
+
let module;
|
|
90
|
+
if (descriptor.format === "commonjs-factory") {
|
|
91
|
+
const exports = loadCommonJs(alias);
|
|
92
|
+
const names = [...new Set(["default", ...Object.keys(exports)])];
|
|
93
|
+
module = new SyntheticModule(names, function () {
|
|
94
|
+
this.setExport("default", exports);
|
|
95
|
+
for (const name of Object.keys(exports))
|
|
96
|
+
this.setExport(name, exports[name]);
|
|
97
|
+
}, { context, identifier: `rea:${alias}` });
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
module = new SourceTextModule(descriptor.source, {
|
|
101
|
+
context,
|
|
102
|
+
identifier: `rea:${alias}`,
|
|
103
|
+
initializeImportMeta: (meta) => {
|
|
104
|
+
meta.url = `rea:${alias}`;
|
|
105
|
+
},
|
|
106
|
+
importModuleDynamically: () => {
|
|
107
|
+
throw new ReplayDeniedError("Dynamic import is unavailable in controlled replay");
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
esmCache.set(alias, module);
|
|
112
|
+
await module.link(async (specifier) => {
|
|
113
|
+
const dependency = descriptor.dependencies[specifier];
|
|
114
|
+
if (dependency === undefined)
|
|
115
|
+
throw new ReplayDeniedError(`Undeclared import: ${specifier}`);
|
|
116
|
+
return loadEsm(dependency);
|
|
117
|
+
});
|
|
118
|
+
await module.evaluate();
|
|
119
|
+
return module;
|
|
120
|
+
};
|
|
121
|
+
const entry = requiredModule(modules, side.entryAlias);
|
|
122
|
+
if (entry.format === "commonjs-factory") {
|
|
123
|
+
const exported = loadCommonJs(side.entryAlias);
|
|
124
|
+
return side.entryExport === "default"
|
|
125
|
+
? (exported.default ?? exported)
|
|
126
|
+
: exported[side.entryExport];
|
|
127
|
+
}
|
|
128
|
+
const namespace = (await loadEsm(side.entryAlias)).namespace;
|
|
129
|
+
return namespace[side.entryExport];
|
|
130
|
+
};
|
|
131
|
+
const deterministicContext = (request, caseIndex) => {
|
|
132
|
+
let state = (request.determinism.randomSeed + caseIndex) >>> 0;
|
|
133
|
+
const random = () => {
|
|
134
|
+
state ^= state << 13;
|
|
135
|
+
state ^= state >>> 17;
|
|
136
|
+
state ^= state << 5;
|
|
137
|
+
return (state >>> 0) / 0x1_0000_0000;
|
|
138
|
+
};
|
|
139
|
+
const epoch = Date.parse(request.determinism.clockIso);
|
|
140
|
+
class ReplayDate extends Date {
|
|
141
|
+
constructor(...arguments_) {
|
|
142
|
+
super(arguments_.length === 0 ? epoch : arguments_[0]);
|
|
143
|
+
}
|
|
144
|
+
static now() {
|
|
145
|
+
return epoch;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const replayMath = Object.create(Math);
|
|
149
|
+
Object.defineProperty(replayMath, "random", { value: random });
|
|
150
|
+
return createContext({ Date: ReplayDate, Math: replayMath }, {
|
|
151
|
+
name: "rea-controlled-replay",
|
|
152
|
+
codeGeneration: { strings: false, wasm: false },
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
const installRspackHelpers = (require_) => {
|
|
156
|
+
require_.d = (exports, definitions) => {
|
|
157
|
+
for (const [name, getter] of Object.entries(definitions))
|
|
158
|
+
if (!Object.prototype.hasOwnProperty.call(exports, name))
|
|
159
|
+
Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
|
160
|
+
};
|
|
161
|
+
require_.r = (exports) => {
|
|
162
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
163
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
164
|
+
};
|
|
165
|
+
require_.n = (module) => {
|
|
166
|
+
const getter = () => (module.__esModule === true ? module.default : module);
|
|
167
|
+
Object.defineProperty(getter, "a", { get: getter });
|
|
168
|
+
return getter;
|
|
169
|
+
};
|
|
170
|
+
require_.nmd = (module) => module;
|
|
171
|
+
};
|
|
172
|
+
const requiredModule = (modules, alias) => {
|
|
173
|
+
const module = modules.get(alias);
|
|
174
|
+
if (module === undefined)
|
|
175
|
+
throw new TypeError(`Undeclared module alias: ${alias}`);
|
|
176
|
+
return module;
|
|
177
|
+
};
|
|
178
|
+
const normalizeFactorySource = (source) => /^\s*\d+\s*\(/u.test(source)
|
|
179
|
+
? source.replace(/^\s*\d+\s*\(/u, "function(")
|
|
180
|
+
: source;
|
|
181
|
+
const projectValue = (value, maximumDepth, maximumNodes) => projectValueRecursive(value, 0, new Set(), {
|
|
182
|
+
maximumDepth,
|
|
183
|
+
maximumNodes,
|
|
184
|
+
nodes: 0,
|
|
185
|
+
});
|
|
186
|
+
const projectValueRecursive = (candidate, depth, ancestors, context) => {
|
|
187
|
+
context.nodes += 1;
|
|
188
|
+
if (context.nodes > context.maximumNodes || depth > context.maximumDepth)
|
|
189
|
+
throw new RangeError("Replay result projection limit exceeded");
|
|
190
|
+
const leaf = projectLeaf(candidate);
|
|
191
|
+
if (leaf !== undefined)
|
|
192
|
+
return leaf;
|
|
193
|
+
if (typeof candidate !== "object" || candidate === null)
|
|
194
|
+
throw new TypeError(`Unsupported replay result type: ${typeof candidate}`);
|
|
195
|
+
if (types.isProxy(candidate))
|
|
196
|
+
throw new TypeError("Proxy replay results are unavailable");
|
|
197
|
+
if (ancestors.has(candidate))
|
|
198
|
+
throw new TypeError("Cyclic replay result");
|
|
199
|
+
ancestors.add(candidate);
|
|
200
|
+
try {
|
|
201
|
+
assertSupportedPrototype(candidate);
|
|
202
|
+
return projectComplexValue(candidate, depth, ancestors, context);
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
ancestors.delete(candidate);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
const projectLeaf = (candidate) => {
|
|
209
|
+
if (candidate === null ||
|
|
210
|
+
typeof candidate === "string" ||
|
|
211
|
+
typeof candidate === "boolean")
|
|
212
|
+
return candidate;
|
|
213
|
+
if (typeof candidate === "number") {
|
|
214
|
+
if (!Number.isFinite(candidate))
|
|
215
|
+
throw new TypeError("Non-finite replay result number");
|
|
216
|
+
return candidate;
|
|
217
|
+
}
|
|
218
|
+
return undefined;
|
|
219
|
+
};
|
|
220
|
+
const assertSupportedPrototype = (candidate) => {
|
|
221
|
+
if (Array.isArray(candidate))
|
|
222
|
+
return;
|
|
223
|
+
const prototype = Object.getPrototypeOf(candidate);
|
|
224
|
+
if (prototype !== null && Object.getPrototypeOf(prototype) !== null)
|
|
225
|
+
throw new TypeError("Unsupported replay result prototype");
|
|
226
|
+
};
|
|
227
|
+
const projectComplexValue = (candidate, depth, ancestors, context) => {
|
|
228
|
+
const descriptors = Object.getOwnPropertyDescriptors(candidate);
|
|
229
|
+
const output = Array.isArray(candidate)
|
|
230
|
+
? []
|
|
231
|
+
: {};
|
|
232
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
233
|
+
if (key === "length" && Array.isArray(candidate))
|
|
234
|
+
continue;
|
|
235
|
+
if (!("value" in descriptor))
|
|
236
|
+
throw new TypeError("Replay result accessors are unavailable");
|
|
237
|
+
if (Array.isArray(output)) {
|
|
238
|
+
if (!/^\d+$/u.test(key))
|
|
239
|
+
throw new TypeError("Replay arrays may only contain indexed values");
|
|
240
|
+
output[Number(key)] = projectValueRecursive(descriptor.value, depth + 1, ancestors, context);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
output[key] = projectValueRecursive(descriptor.value, depth + 1, ancestors, context);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return output;
|
|
247
|
+
};
|
|
248
|
+
const exceptionOutcome = (replayCase, outcome, error, maximumBytes) => {
|
|
249
|
+
const details = exceptionDetails(error);
|
|
250
|
+
const name = bounded(details.name, maximumBytes);
|
|
251
|
+
const message = bounded(details.message, maximumBytes);
|
|
252
|
+
const stack = details.stack === null ? null : bounded(details.stack, maximumBytes);
|
|
253
|
+
return {
|
|
254
|
+
case_id: replayCase.caseId,
|
|
255
|
+
outcome,
|
|
256
|
+
exception: { name, message, stack },
|
|
257
|
+
input_sha256: replayCase.inputSha256,
|
|
258
|
+
output_sha256: null,
|
|
259
|
+
truncated: false,
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
const exceptionDetails = (error) => {
|
|
263
|
+
if (typeof error !== "object" || error === null)
|
|
264
|
+
return { name: "Error", message: "Unknown replay exception", stack: null };
|
|
265
|
+
if (types.isProxy(error))
|
|
266
|
+
return { name: "Error", message: "Proxy replay exception", stack: null };
|
|
267
|
+
const own = Object.getOwnPropertyDescriptors(error);
|
|
268
|
+
const prototype = Object.getPrototypeOf(error);
|
|
269
|
+
const inherited = prototype === null ? {} : Object.getOwnPropertyDescriptors(prototype);
|
|
270
|
+
const stringValue = (descriptor) => descriptor !== undefined &&
|
|
271
|
+
"value" in descriptor &&
|
|
272
|
+
typeof descriptor.value === "string"
|
|
273
|
+
? descriptor.value
|
|
274
|
+
: null;
|
|
275
|
+
return {
|
|
276
|
+
name: stringValue(own.name) ?? stringValue(inherited.name) ?? "Error",
|
|
277
|
+
message: stringValue(own.message) ?? "Unknown replay exception",
|
|
278
|
+
stack: stringValue(own.stack),
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
const bounded = (value, maximumBytes) => {
|
|
282
|
+
const bytes = Buffer.from(value);
|
|
283
|
+
if (bytes.byteLength <= maximumBytes)
|
|
284
|
+
return value;
|
|
285
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
286
|
+
for (let end = maximumBytes; end >= Math.max(0, maximumBytes - 3); end -= 1) {
|
|
287
|
+
try {
|
|
288
|
+
return decoder.decode(bytes.subarray(0, end));
|
|
289
|
+
}
|
|
290
|
+
catch {
|
|
291
|
+
/* try the preceding UTF-8 boundary */
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return "";
|
|
295
|
+
};
|
|
296
|
+
void main().catch((error) => {
|
|
297
|
+
const message = error instanceof Error ? error.message : "Replay worker failed";
|
|
298
|
+
process.stderr.write(message.slice(0, 4096));
|
|
299
|
+
process.exitCode = 70;
|
|
300
|
+
});
|