rea-agents 6.0.0 → 6.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 +23 -17
- package/bridge/android/ReaJadxBridge.java +14 -5
- package/bridge/ghidra/ReaGhidraBridge.java +173 -47
- package/bridge/hopper_bridge.py +310 -128
- package/bridge/mitmproxy/capture.py +0 -2
- package/bridge/native/rea_lldb_tracer.py +630 -94
- package/bridge/process/ProcessRunTokenReader.swift +39 -5
- package/bridge/pwntools/recorded_crash_impl.py +4 -0
- package/dist/android/JadxConfiguration.js +196 -33
- package/dist/android/JadxMcpTransport.js +4 -0
- package/dist/android/JadxProtocol.js +6 -0
- package/dist/android/JadxProvider.js +19 -2
- package/dist/android/JadxSession.js +23 -4
- package/dist/application/AnalysisContextQueries.js +8 -35
- package/dist/application/AnalysisDocument.js +32 -0
- package/dist/application/AppBundleExecutable.js +67 -21
- package/dist/application/CallPathTracing.js +19 -3
- package/dist/application/CapabilityInventory.js +6 -3
- package/dist/application/ClientConfigurationDocument.js +871 -6
- package/dist/application/ClientRegistrationIdentity.js +26 -5
- package/dist/application/ClientRegistrationStatus.js +29 -14
- package/dist/application/DirectAnalysis.js +27 -37
- package/dist/application/Doctor.js +4 -2
- package/dist/application/DoctorScope.js +25 -13
- package/dist/application/EnhancedLiteralTracing.js +22 -25
- package/dist/application/EnhancedTools.js +13 -11
- package/dist/application/EvidenceBundleFiles.js +23 -11
- package/dist/application/FunctionAnalysisEvidence.js +2 -3
- package/dist/application/InventoryProjectionEvidence.js +4 -3
- package/dist/application/InvestigationProviders.js +3 -2
- package/dist/application/JsonFiles.js +50 -28
- package/dist/application/ProcedureAddressResolution.js +11 -0
- package/dist/application/ReconstructionCoverageService.js +7 -4
- package/dist/application/ReconstructionObligationLedgerService.js +4 -3
- package/dist/application/Setup.js +13 -1
- package/dist/application/SetupClientConfiguration.js +10 -15
- package/dist/application/SetupHost.js +5 -2
- package/dist/application/SetupPlan.js +5 -3
- package/dist/application/SupportedClients.js +34 -1
- package/dist/application/Uninstall.js +4 -3
- package/dist/application/Update.js +18 -3
- package/dist/application/UpdateRuntime.js +46 -25
- package/dist/application/WebModuleTraceService.js +4 -2
- package/dist/application/WebNetworkCaptureService.js +4 -2
- package/dist/application/WebRuntimeService.js +5 -3
- package/dist/application/WebScriptExportService.js +2 -2
- package/dist/application/WebSourceLocationService.js +4 -2
- package/dist/application/WorkflowEvidence.js +82 -0
- package/dist/application/binary/AnalysisProviderEvaluation.js +21 -5
- package/dist/application/binary/AnalysisProviderRegistry.js +2 -0
- package/dist/application/binary/AnalysisSnapshotCache.js +3 -6
- package/dist/application/binary/BinarySession.js +95 -68
- package/dist/application/binary/BinarySessionOpen.js +3 -3
- package/dist/application/binary/BinarySessionRecords.js +25 -3
- package/dist/application/binary/BinarySessionStatus.js +17 -1
- package/dist/application/binary/CompositeProvider.js +13 -0
- package/dist/application/binary/LazyAnalysisProvider.js +3 -0
- package/dist/application/binaryDiagnostics/BinaryLayoutService.js +4 -2
- package/dist/application/binaryDiagnostics/RecordedCrashService.js +4 -2
- package/dist/application/evm/EvmInterfaceService.js +4 -2
- package/dist/application/investigation/EvidenceLedger.js +21 -7
- package/dist/application/investigation/InvestigationRecords.js +8 -0
- package/dist/application/javascript/JavaScriptAnalysisControl.js +34 -0
- package/dist/application/javascript/JavaScriptApplicationEvidence.js +24 -3
- package/dist/application/javascript/JavaScriptApplicationEvidenceGraph.js +19 -2
- package/dist/application/javascript/JavaScriptApplicationService.js +22 -15
- package/dist/application/javascript/JavaScriptApplicationWorkflowService.js +5 -5
- package/dist/application/javascript/JavaScriptArtifactAnalysis.js +5 -4
- package/dist/application/javascript/JavaScriptArtifactGraphBuilder.js +39 -7
- package/dist/application/javascript/JavaScriptArtifactPathResolution.js +6 -3
- package/dist/application/javascript/JavaScriptArtifactReconstruction.js +11 -3
- package/dist/application/javascript/JavaScriptModuleRelationships.js +37 -8
- package/dist/application/javascript/JavaScriptRecoveryService.js +4 -2
- package/dist/application/javascript/JavaScriptRuntimeObservationService.js +3 -1
- package/dist/application/javascript/JavaScriptRuntimeReconciliationService.js +3 -3
- package/dist/application/javascript/JavaScriptSemanticGraphBuilder.js +63 -61
- package/dist/application/javascript/JavaScriptSemanticGraphValueProjection.js +23 -1
- package/dist/application/managed/ManagedApplicationGraphService.js +4 -3
- package/dist/application/managed/ManagedMemberComparisonService.js +7 -4
- package/dist/application/managed/ManagedNativeVerificationService.js +4 -3
- package/dist/application/managed/ManagedReconstructionService.js +4 -3
- package/dist/application/process/ProcessCli.js +14 -6
- package/dist/application/process/ProcessEvidence.js +4 -3
- package/dist/application/workflowInputError.js +18 -0
- package/dist/artifacts/ArtifactProvider.js +12 -2
- package/dist/artifacts/MachOSliceArtifactReader.js +98 -14
- package/dist/artifacts/NativeDmgArtifactReader.js +13 -6
- package/dist/artifacts/apple/AppleAssetCatalogAnalysis.js +22 -3
- package/dist/artifacts/apple/InterfaceBuilderAnalysis.js +176 -56
- package/dist/artifacts/apple/InterfaceBuilderDecodeBudget.js +195 -0
- package/dist/artifacts/apple/KeyedArchiveReader.js +36 -22
- package/dist/artifacts/apple/MachoLoadCommandReader.js +92 -31
- package/dist/artifacts/apple/NibArchive.js +81 -14
- package/dist/artifacts/apple/NibViewHierarchy.js +10 -3
- package/dist/artifacts/apple/PlistNumberLiterals.js +164 -0
- package/dist/artifacts/inventory/ArtifactGraphConstruction.js +13 -8
- package/dist/artifacts/inventory/scanCanonical.js +11 -14
- package/dist/artifacts/javascript/JavaScriptArtifactFiles.js +6 -2
- package/dist/browser/CdpCaptureCompleteness.js +2 -0
- package/dist/browser/CdpCaptureEventHandlers.js +76 -11
- package/dist/browser/CdpCaptureEventTypes.js +5 -1
- package/dist/browser/CdpCaptureEvents.js +25 -0
- package/dist/browser/CdpConnection.js +30 -11
- package/dist/browser/CdpOptionalCommand.js +2 -3
- package/dist/browser/CdpPageCapture.js +23 -1
- package/dist/browser/PlaywrightElectronActiveActions.js +32 -23
- package/dist/browser/PlaywrightElectronActiveProjection.js +141 -0
- package/dist/browser/PlaywrightElectronActiveProvider.js +123 -124
- package/dist/browser/WebSourceMapFetcher.js +426 -72
- package/dist/browser/assets/LocalWebScriptArtifacts.js +2 -2
- package/dist/browser/history/CaptureFailures.js +37 -1
- package/dist/browser/history/CaptureRelease.js +5 -0
- package/dist/browser/history/HarCaptureAdapter.js +3 -3
- package/dist/browser/history/HarJson.js +3 -2
- package/dist/browser/history/HistoricalCaptureDecoder.js +4 -2
- package/dist/cli/analysisSelector.js +23 -0
- package/dist/cli/applicationCommands.js +2 -3
- package/dist/cli/coreBinaryCommands.js +70 -12
- package/dist/cli/electronCommands.js +7 -6
- package/dist/cli/javascriptApplicationAnalysis.js +7 -3
- package/dist/cli/jsonOutput.js +4 -99
- package/dist/cli/nativeCallCommands.js +2 -3
- package/dist/cli/webRuntimeCommands.js +8 -8
- package/dist/cli.js +2 -1
- package/dist/cliCommandNames.js +0 -1
- package/dist/cliJsonInput.js +9 -4
- package/dist/config/environment.js +4 -0
- package/dist/config/ghidraStartupTimeout.js +17 -0
- package/dist/config/mcpResponseBudget.js +22 -0
- package/dist/config/parseConfig.js +2 -1
- package/dist/contracts/enhancedInputs.js +5 -3
- package/dist/contracts/enhancedToolContracts.js +3 -3
- package/dist/contracts/hopperMemoryContracts.js +2 -5
- package/dist/contracts/javascript/electronToolContracts.js +1 -1
- package/dist/contracts/managed/managedToolContracts.js +2 -4
- package/dist/contracts/native/nativeToolContracts.js +4 -2
- package/dist/contracts/officialToolContracts.js +14 -15
- package/dist/contracts/promptContracts.js +3 -3
- package/dist/contracts/sessionLifecycleInputs.js +3 -7
- package/dist/contracts/sessionStatusContract.js +2 -4
- package/dist/contracts/sessionToolContracts.js +4 -6
- package/dist/contracts/sessionToolSchemas.js +2 -5
- package/dist/contracts/toolContractExamples.js +0 -1
- package/dist/contracts/toolContractHelpers.js +4 -1
- package/dist/contracts/toolEffects.js +0 -1
- package/dist/contracts/toolOutputSchemaGroups.js +28 -27
- package/dist/contracts/toolOutputSchemaPrimitives.js +18 -0
- package/dist/contracts/toolSchemaMetadata.js +69 -10
- package/dist/contracts/webNetworkCaptureToolContracts.js +1 -1
- package/dist/domain/analysisErrorBase.js +8 -3
- package/dist/domain/analysisErrorCore.js +3 -1
- package/dist/domain/analysisErrorPresentation.js +72 -17
- package/dist/domain/analysisErrorProjection.js +106 -27
- package/dist/domain/android/androidAnalysis.js +2 -4
- package/dist/domain/android/androidApplication.js +17 -9
- package/dist/domain/apple/appleApplication.js +41 -14
- package/dist/domain/apple/dyldEnvironment.js +73 -0
- package/dist/domain/apple/dylibResolution.js +120 -9
- package/dist/domain/apple/dylibResolutionFindings.js +9 -7
- package/dist/domain/apple/interfaceBuilderGraph.js +25 -13
- package/dist/domain/apple/interfaceBuilderKeyedArchive.js +13 -3
- package/dist/domain/apple/keyedArchive.js +9 -1
- package/dist/domain/apple/machoContainer.js +54 -0
- package/dist/domain/apple/plistNumbers.js +76 -0
- package/dist/domain/artifactIdentity.js +29 -0
- package/dist/domain/artifactInventoryEvidence.js +19 -24
- package/dist/domain/bridgeCandidateProjection.js +71 -0
- package/dist/domain/browserCompleteness.js +1 -0
- package/dist/domain/browserObservationError.js +24 -5
- package/dist/domain/browserScenarioValues.js +2 -6
- package/dist/domain/bundleComparison.js +3 -2
- package/dist/domain/canonicalJsonDigestSteps.js +133 -0
- package/dist/domain/canonicalOrdering.js +9 -5
- package/dist/domain/changedBehavior.js +6 -6
- package/dist/domain/comparisonSourceEvidence.js +40 -0
- package/dist/domain/configurationErrors.js +1 -1
- package/dist/domain/evidence.js +64 -9
- package/dist/domain/evidenceBundle.js +42 -1
- package/dist/domain/evidenceErrors.js +12 -1
- package/dist/domain/explicitSensitiveFailure.js +17 -1
- package/dist/domain/firmware/firmwareAnalysis.js +6 -7
- package/dist/domain/hopperErrors.js +23 -2
- package/dist/domain/hopperValues.js +51 -8
- package/dist/domain/immutableJson.js +114 -0
- package/dist/domain/inputIssueProjection.js +3 -0
- package/dist/domain/javascript/electronActiveObservation.js +30 -4
- package/dist/domain/javascript/electronStaticAnalysisValues.js +6 -12
- package/dist/domain/javascript/javascriptApplicationAnalysis.js +71 -23
- package/dist/domain/javascript/javascriptApplicationGraph.js +13 -0
- package/dist/domain/javascript/javascriptAstValues.js +20 -0
- package/dist/domain/javascript/javascriptRecovery.js +3 -8
- package/dist/domain/javascript/javascriptSemanticAnalysis.js +97 -2
- package/dist/domain/javascript/javascriptSemanticCoverage.js +6 -5
- package/dist/domain/javascript/javascriptSemanticDataEffectHelpers.js +9 -17
- package/dist/domain/javascript/javascriptSemanticDataEffects.js +22 -5
- package/dist/domain/javascript/javascriptSemanticGraph.js +13 -0
- package/dist/domain/javascript/javascriptSemanticGraphSchemas.js +1 -0
- package/dist/domain/javascript/javascriptSemanticPrimitives.js +25 -17
- package/dist/domain/javascript/javascriptSemanticQuerySchemas.js +8 -4
- package/dist/domain/javascript/javascriptSemanticResourceLimits.js +77 -0
- package/dist/domain/javascript/javascriptSemanticValues.js +83 -11
- package/dist/domain/javascript/javascriptSourceParser.js +6 -2
- package/dist/domain/javascript/javascriptStaticAnalysis.js +22 -17
- package/dist/domain/javascript/javascriptStaticAnalysisBundler.js +5 -3
- package/dist/domain/javascript/javascriptStaticAnalysisCalls.js +14 -4
- package/dist/domain/javascript/javascriptStaticAnalysisFindings.js +66 -7
- package/dist/domain/javascript/javascriptStaticAnalysisHelpers.js +28 -16
- package/dist/domain/javascript/javascriptStaticAnalysisState.js +3 -2
- package/dist/domain/jsonSerialization.js +109 -0
- package/dist/domain/jsonValue.js +90 -6
- package/dist/domain/localPath.js +6 -0
- package/dist/domain/managed/managedApplicationGraph.js +10 -10
- package/dist/domain/managed/managedInspectionEvidence.js +16 -0
- package/dist/domain/managed/managedMemberComparisonMatch.js +5 -9
- package/dist/domain/managed/managedNativeVerification.js +3 -9
- package/dist/domain/native/fileOffsetPartialObservation.js +1 -0
- package/dist/domain/native/nativeCallObservation.js +33 -11
- package/dist/domain/native/nativeCallPartialObservation.js +33 -0
- package/dist/domain/process/processCapture.js +8 -4
- package/dist/domain/process/processComparison.js +38 -4
- package/dist/domain/process/processScenario.js +11 -10
- package/dist/domain/propertyListKeys.js +1 -1
- package/dist/domain/propertyListXmlText.js +19 -0
- package/dist/domain/providerAdapterError.js +1 -1
- package/dist/domain/providerOperationHealth.js +54 -0
- package/dist/domain/reconstructionVerification.js +6 -43
- package/dist/domain/reconstructionVerificationSchemas.js +2 -2
- package/dist/domain/staticRuntimeCorrelation.js +6 -43
- package/dist/domain/webBundleAnalysis.js +20 -8
- package/dist/domain/webBundleAnalyzerInspection.js +13 -8
- package/dist/domain/webBundleAnalyzerResult.js +41 -2
- package/dist/domain/webRuntime.js +19 -5
- package/dist/domain/webSourceLocation.js +1 -0
- package/dist/firmware/FirmwareFiles.js +1 -1
- package/dist/generatedPackageMetadata.js +1 -1
- package/dist/ghidra/GhidraAnalysisProfile.js +5 -0
- package/dist/ghidra/GhidraClient.js +47 -14
- package/dist/ghidra/GhidraDiagnostics.js +7 -7
- package/dist/ghidra/GhidraFunctionValues.js +10 -7
- package/dist/ghidra/GhidraInstallation.js +18 -21
- package/dist/ghidra/GhidraInventoryValues.js +14 -4
- package/dist/ghidra/GhidraJavaLaunch.js +62 -0
- package/dist/ghidra/GhidraLauncher.js +33 -16
- package/dist/ghidra/GhidraProviderCapabilities.js +14 -2
- package/dist/ghidra/GhidraProviderClient.js +23 -12
- package/dist/ghidra/GhidraSessionError.js +11 -7
- package/dist/ghidra/GhidraTargetSnapshot.js +47 -12
- package/dist/ghidra/GhidraTransport.js +20 -0
- package/dist/hopper/BridgeLauncher.js +31 -11
- package/dist/hopper/HopperAnalysisProfile.js +62 -4
- package/dist/hopper/HopperCleanup.js +15 -3
- package/dist/hopper/HopperClient.js +222 -14
- package/dist/hopper/HopperFileOffset.js +237 -0
- package/dist/hopper/HopperMachOImage.js +196 -0
- package/dist/hopper/HopperOperationStage.js +6 -0
- package/dist/hopper/HopperProvider.js +63 -9
- package/dist/hopper/HopperProviderCapabilities.js +19 -1
- package/dist/hopper/HopperRegexSearch.js +137 -0
- package/dist/hopper/HopperRegexWorker.js +27 -0
- package/dist/hopper/HopperRequestQueue.js +68 -19
- package/dist/hopper/HopperTargetLease.js +3 -2
- package/dist/inspector/JavaScriptRuntimeScope.js +9 -1
- package/dist/inspector/V8InspectorCaptureProjection.js +8 -3
- package/dist/inspector/V8InspectorProvider.js +47 -11
- package/dist/javascript/sourceMaps/DecodedSourceMap.js +47 -0
- package/dist/javascript/sourceMaps/SourceMapCommand.js +16 -0
- package/dist/javascript/sourceMaps/SourceMapFormat.js +79 -31
- package/dist/javascript/sourceMaps/TraceSourceMap.js +14 -28
- package/dist/mcpDoctor.js +62 -2
- package/dist/native/AppleDispatchCoverage.js +47 -6
- package/dist/native/AppleDispatchDecodeFacts.js +6 -0
- package/dist/native/AppleDispatchMetadata.js +6 -3
- package/dist/native/AppleMachoFixups.js +48 -24
- package/dist/native/AppleMachoSelection.js +32 -16
- package/dist/native/AppleObjcCategories.js +6 -2
- package/dist/native/AppleObjcDispatchFacets.js +5 -2
- package/dist/native/AppleObjcProperties.js +2 -1
- package/dist/native/AppleSwiftDispatchFacets.js +27 -21
- package/dist/native/AppleSwiftVtables.js +21 -15
- package/dist/native/CommandRunner.js +81 -84
- package/dist/native/LldbCallTracer.js +365 -102
- package/dist/native/LldbRetainedObservations.js +178 -0
- package/dist/native/NativeCallObservation.js +62 -3
- package/dist/native/NativeMacOSProvider.js +98 -17
- package/dist/native/SignatureTargetBinding.js +155 -0
- package/dist/native/parsers/lipo.js +71 -1
- package/dist/native/pwndbg/PwndbgCoreContext.js +25 -5
- package/dist/native/pwntools/RecordedCrashStructureBindings.js +2 -0
- package/dist/process/DarwinProcessRunTokenReader.js +8 -9
- package/dist/process/ExecFileOutput.js +20 -0
- package/dist/process/OwnedCommand.js +7 -2
- package/dist/process/ProcessOwnership.js +203 -53
- package/dist/process/ProcessOwnershipObservation.js +49 -4
- package/dist/process/ProviderProcess.js +38 -7
- package/dist/process/capture/ProcessCaptureError.js +2 -2
- package/dist/process/capture/ProcessCaptureLifecycle.js +100 -34
- package/dist/server/EvidenceMcpServer.js +146 -0
- package/dist/server/createServer.js +15 -8
- package/dist/server/registerAndroidTools.js +2 -4
- package/dist/server/registerApplicationTools/helpers.js +2 -4
- package/dist/server/registerArtifactComparisonTool.js +11 -7
- package/dist/server/registerBinaryDiagnosticsTools.js +2 -4
- package/dist/server/registerBrowserScenarioTool.js +2 -4
- package/dist/server/registerBrowserTools.js +2 -4
- package/dist/server/registerBundleComparisonTool.js +2 -3
- package/dist/server/registerCloseLifecycleTool.js +8 -18
- package/dist/server/registerElectronTools.js +2 -4
- package/dist/server/registerEnhancedTools.js +18 -59
- package/dist/server/registerEvidenceTools.js +2 -4
- package/dist/server/registerEvmTools.js +2 -4
- package/dist/server/registerFirmwareTools.js +2 -4
- package/dist/server/registerFunctionComparisonTool.js +10 -6
- package/dist/server/registerInvestigationTools.js +7 -7
- package/dist/server/registerJavaScriptRecoveryTool.js +2 -4
- package/dist/server/registerJavaScriptRuntimeObservationTools.js +2 -4
- package/dist/server/registerManagedWorkflowTools/compareManagedMembers.js +2 -4
- package/dist/server/registerManagedWorkflowTools/importManagedReconstruction.js +2 -4
- package/dist/server/registerManagedWorkflowTools/projectManagedApplicationGraph.js +2 -4
- package/dist/server/registerManagedWorkflowTools/verifyManagedNativeBoundaries.js +2 -4
- package/dist/server/registerOfficialTools.js +2 -4
- package/dist/server/registerProcessComparisonTool.js +71 -45
- package/dist/server/registerRecordedCrashTools.js +2 -4
- package/dist/server/registerSessionRecordTools.js +5 -6
- package/dist/server/registerSessionStatusTool.js +17 -3
- package/dist/server/registerSessionTools.js +11 -3
- package/dist/server/registerWebModuleTool.js +2 -4
- package/dist/server/registerWebNetworkCaptureTool.js +2 -4
- package/dist/server/registerWebRuntimeTools.js +3 -7
- package/dist/server/registerWebScriptTool.js +2 -4
- package/dist/server/registerWebSourceLocationTool.js +2 -4
- package/dist/server/runDerivedOperation.js +15 -3
- package/dist/server/sessionAvailabilityPolicy.js +0 -1
- package/dist/server/toolRegistrationOptions.js +2 -2
- package/dist/server/toolResult.js +62 -10
- package/dist/server/toolResultEncoding.js +33 -0
- package/install.sh +1 -1
- package/native/windows/build/manifest.json +1 -1
- package/package.json +8 -3
- package/scripts/electron-active-hook-boundaries.cjs +18 -20
- package/scripts/electron-active-hook.cjs +241 -37
- package/skills/reverse-engineer-anything/SKILL.md +11 -3
- package/skills/reverse-engineer-anything/references/javascript-applications.md +8 -1
- package/dist/ghidra/GhidraDefaults.js +0 -2
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { javascriptApplicationGraphSchema } from "./javascriptApplicationGraph.js";
|
|
3
|
-
import { javaScriptSemanticGraphSchema } from "./javascriptSemanticGraph.js";
|
|
2
|
+
import { javascriptApplicationGraphSchema, isValidatedImmutableJavaScriptApplicationGraph, } from "./javascriptApplicationGraph.js";
|
|
3
|
+
import { javaScriptSemanticGraphSchema, isValidatedImmutableJavaScriptSemanticGraph, } from "./javascriptSemanticGraph.js";
|
|
4
4
|
import { digestSchema } from "../digests.js";
|
|
5
5
|
import { prefixedDigestSchema } from "../digests.js";
|
|
6
|
+
import { localPathStringSchema } from "../localPath.js";
|
|
6
7
|
const countSchema = z.number().int().min(0);
|
|
7
8
|
/** Public target-free request for static JavaScript application analysis. */
|
|
8
9
|
export const analyzeJavaScriptApplicationInputSchema = z.strictObject({
|
|
9
|
-
input_path:
|
|
10
|
+
input_path: localPathStringSchema,
|
|
10
11
|
format: z.enum(["auto", "asar", "directory"]).default("auto"),
|
|
11
12
|
});
|
|
12
13
|
/** Compact counts for the high-level Electron architecture/security surface. */
|
|
@@ -45,9 +46,7 @@ const reconstructionStatisticsSchema = z.strictObject({
|
|
|
45
46
|
parse_failures: countSchema,
|
|
46
47
|
truncated_scopes: countSchema,
|
|
47
48
|
});
|
|
48
|
-
|
|
49
|
-
export const javascriptApplicationAnalysisResultSchema = z
|
|
50
|
-
.strictObject({
|
|
49
|
+
const applicationAnalysisResultShape = z.strictObject({
|
|
51
50
|
input_path: z.string().min(1),
|
|
52
51
|
format: z.enum(["asar", "directory"]),
|
|
53
52
|
root_artifact_sha256: digestSchema,
|
|
@@ -58,8 +57,8 @@ export const javascriptApplicationAnalysisResultSchema = z
|
|
|
58
57
|
statistics: reconstructionStatisticsSchema,
|
|
59
58
|
limitations: z.array(z.string().min(1)),
|
|
60
59
|
semantic_graph: javaScriptSemanticGraphSchema,
|
|
61
|
-
})
|
|
62
|
-
|
|
60
|
+
});
|
|
61
|
+
function* checkApplicationBindingsSteps(result, context) {
|
|
63
62
|
if (result.semantic_graph.application_graph_id !== result.graph.graph_id)
|
|
64
63
|
context.addIssue({
|
|
65
64
|
code: "custom",
|
|
@@ -72,19 +71,68 @@ export const javascriptApplicationAnalysisResultSchema = z
|
|
|
72
71
|
path: ["semantic_graph", "root_artifact_sha256"],
|
|
73
72
|
message: "Semantic graph must commit the containing root artifact",
|
|
74
73
|
});
|
|
75
|
-
const applicationNodeIds = new Set(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
74
|
+
const applicationNodeIds = new Set();
|
|
75
|
+
let examined = 0;
|
|
76
|
+
try {
|
|
77
|
+
for (const node of result.graph.nodes) {
|
|
78
|
+
applicationNodeIds.add(node.node_id);
|
|
79
|
+
if (++examined === 4096) {
|
|
80
|
+
examined = 0;
|
|
81
|
+
yield;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
for (const [nodeIndex, node] of result.semantic_graph.nodes.entries()) {
|
|
85
|
+
if (++examined === 4096) {
|
|
86
|
+
examined = 0;
|
|
87
|
+
yield;
|
|
88
|
+
}
|
|
89
|
+
for (const [identifierIndex, identifier,] of node.application_node_ids.entries()) {
|
|
90
|
+
if (!applicationNodeIds.has(identifier))
|
|
91
|
+
context.addIssue({
|
|
92
|
+
code: "custom",
|
|
93
|
+
path: [
|
|
94
|
+
"semantic_graph",
|
|
95
|
+
"nodes",
|
|
96
|
+
nodeIndex,
|
|
97
|
+
"application_node_ids",
|
|
98
|
+
identifierIndex,
|
|
99
|
+
],
|
|
100
|
+
message: "Semantic node references an absent application node",
|
|
101
|
+
});
|
|
102
|
+
if (++examined === 4096) {
|
|
103
|
+
examined = 0;
|
|
104
|
+
yield;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
applicationNodeIds.clear();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** JavaScript application analysis with an authenticated semantic companion. */
|
|
114
|
+
export const javascriptApplicationAnalysisResultSchema = applicationAnalysisResultShape.superRefine((result, context) => {
|
|
115
|
+
const steps = checkApplicationBindingsSteps(result, context);
|
|
116
|
+
while (!steps.next().done) {
|
|
117
|
+
// Public/imported results still receive complete synchronous validation.
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
const ownedAnalysisResultShape = applicationAnalysisResultShape.extend({
|
|
121
|
+
graph: z.custom(isValidatedImmutableJavaScriptApplicationGraph),
|
|
122
|
+
semantic_graph: z.custom(isValidatedImmutableJavaScriptSemanticGraph),
|
|
90
123
|
});
|
|
124
|
+
/** Reuse exact owned graphs while validating metadata and cross-graph bindings. */
|
|
125
|
+
export function* parseOwnedJavaScriptApplicationAnalysisSteps(input) {
|
|
126
|
+
const prepared = ownedAnalysisResultShape.safeParse(input);
|
|
127
|
+
if (!prepared.success)
|
|
128
|
+
return javascriptApplicationAnalysisResultSchema.parse(input);
|
|
129
|
+
const issues = [];
|
|
130
|
+
yield* checkApplicationBindingsSteps(prepared.data, {
|
|
131
|
+
addIssue: (issue) => {
|
|
132
|
+
issues.push(issue);
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
if (issues.length > 0)
|
|
136
|
+
throw new z.ZodError(issues);
|
|
137
|
+
return prepared.data;
|
|
138
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { canonicalDigest, canonicalJson } from "../comparisonSemantics.js";
|
|
3
3
|
import { compareCodePoints, uniqueSorted } from "../canonicalOrdering.js";
|
|
4
|
+
import { freezeOwnedJsonSnapshotSteps } from "../immutableJson.js";
|
|
4
5
|
import { applicationEdgeInputSchema, applicationEdgeSchema, applicationNodeInputSchema, applicationNodeObservationSchema, applicationNodeSchema, javascriptApplicationGraphInputSchema, javascriptApplicationGraphRecordSchema, } from "./javascriptApplicationGraphSchemas.js";
|
|
5
6
|
const OBSERVATION_IDENTIFIER_STRATEGY = {
|
|
6
7
|
strategy: "semantic-content-sha256",
|
|
@@ -255,6 +256,18 @@ export const createJavaScriptApplicationGraph = (input) => {
|
|
|
255
256
|
graph_id: `jag_${canonicalDigest(semantic, "JavaScript Application Graph")}`,
|
|
256
257
|
});
|
|
257
258
|
};
|
|
259
|
+
const validatedImmutableApplicationGraphs = new WeakSet();
|
|
260
|
+
/** Clone and validate synchronously, then return steps to seal the owned graph. */
|
|
261
|
+
export const createImmutableJavaScriptApplicationGraphSteps = (input) => sealValidatedApplicationGraphSteps(createJavaScriptApplicationGraph(input));
|
|
262
|
+
function* sealValidatedApplicationGraphSteps(graph) {
|
|
263
|
+
yield* freezeOwnedJsonSnapshotSteps(graph);
|
|
264
|
+
validatedImmutableApplicationGraphs.add(graph);
|
|
265
|
+
return graph;
|
|
266
|
+
}
|
|
267
|
+
/** Recognize the exact completely sealed graph produced by the owned factory. */
|
|
268
|
+
export const isValidatedImmutableJavaScriptApplicationGraph = (value) => typeof value === "object" &&
|
|
269
|
+
value !== null &&
|
|
270
|
+
validatedImmutableApplicationGraphs.has(value);
|
|
258
271
|
/** Parse a stored graph and reject stale IDs. */
|
|
259
272
|
export const parseJavaScriptApplicationGraph = (input) => javascriptApplicationGraphSchema.parse(input);
|
|
260
273
|
/** Compute the byte-stable SHA-256 commitment of a verified graph. */
|
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
import * as t from "@babel/types";
|
|
2
|
+
/** Read one syntax-level primitive only when its value is exact. */
|
|
3
|
+
export const readExactJavaScriptLiteral = (node) => {
|
|
4
|
+
if (t.isStringLiteral(node))
|
|
5
|
+
return { found: true, value: node.value };
|
|
6
|
+
if (t.isNumericLiteral(node) && Number.isFinite(node.value))
|
|
7
|
+
return { found: true, value: node.value };
|
|
8
|
+
if (t.isBooleanLiteral(node))
|
|
9
|
+
return { found: true, value: node.value };
|
|
10
|
+
if (t.isNullLiteral(node))
|
|
11
|
+
return { found: true, value: null };
|
|
12
|
+
if (t.isTemplateLiteral(node) &&
|
|
13
|
+
node.expressions.length === 0 &&
|
|
14
|
+
node.quasis.length === 1) {
|
|
15
|
+
const cooked = node.quasis[0]?.value.cooked;
|
|
16
|
+
return cooked === null || cooked === undefined
|
|
17
|
+
? { found: false }
|
|
18
|
+
: { found: true, value: cooked };
|
|
19
|
+
}
|
|
20
|
+
return { found: false };
|
|
21
|
+
};
|
|
2
22
|
/** Read an identifier or literal property name without evaluating syntax. */
|
|
3
23
|
export const propertyName = (node) => {
|
|
4
24
|
if (t.isIdentifier(node))
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { digestSchema } from "../digests.js";
|
|
3
3
|
import { analyzeJavaScriptApplicationInputSchema } from "./javascriptApplicationAnalysis.js";
|
|
4
|
+
import { localPathStringSchema } from "../localPath.js";
|
|
4
5
|
/** Recover derived readable modules from one explicitly selected local script. */
|
|
5
6
|
export const javascriptRecoveryInputSchema = z.strictObject({
|
|
6
|
-
path:
|
|
7
|
-
|
|
8
|
-
.min(1)
|
|
9
|
-
.describe("Absolute path to a UTF-8 JavaScript file; never executed"),
|
|
10
|
-
output_directory: z
|
|
11
|
-
.string()
|
|
12
|
-
.min(1)
|
|
13
|
-
.describe("Absolute absent output directory; parent must exist"),
|
|
7
|
+
path: localPathStringSchema.describe("Absolute path to a UTF-8 JavaScript file; never executed"),
|
|
8
|
+
output_directory: localPathStringSchema.describe("Absolute absent output directory; parent must exist"),
|
|
14
9
|
extraction_mode: z
|
|
15
10
|
.enum(["structural", "heuristic", "inspection"])
|
|
16
11
|
.default("structural")
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import * as t from "@babel/types";
|
|
2
2
|
import { failedJavaScriptSemanticIr, } from "./javascriptSemanticIr.js";
|
|
3
3
|
import { collectSemanticModuleLink, collectSemanticCallable, collectSemanticReferences, immutableSemanticBindings, immutableSemanticScopes, semanticStaticPropertyKey, } from "./javascriptSemanticProjection.js";
|
|
4
|
-
import { currentSemanticScope, resolveSemanticBindingFromScope, semanticScopeId, semanticVariableScope, } from "./javascriptSemanticState.js";
|
|
4
|
+
import { currentSemanticScope, resolveSemanticBindingState, semanticResolutionBlocked, resolveSemanticBindingFromScope, semanticScopeId, semanticVariableScope, } from "./javascriptSemanticState.js";
|
|
5
5
|
import { traverseJavaScriptAst } from "./javascriptSemanticTraversal.js";
|
|
6
6
|
import { collectSemanticMemberMutations } from "./javascriptSemanticMemberMutations.js";
|
|
7
7
|
import { collectSemanticReturns, resolveSemanticModuleCallables, } from "./javascriptSemanticReturns.js";
|
|
8
8
|
import { collectJavaScriptDerivedSemantics } from "./javascriptSemanticDerivedAnalysis.js";
|
|
9
9
|
import { propertyName, range } from "./javascriptStaticAnalysisHelpers.js";
|
|
10
10
|
import { semanticCoverage } from "./javascriptSemanticCoverage.js";
|
|
11
|
+
import { semanticResourceLimitsIn } from "./javascriptSemanticResourceLimits.js";
|
|
11
12
|
import { parseJavaScriptSource, } from "./javascriptSourceParser.js";
|
|
12
13
|
/** Recover lexical bindings, aliases, constants, and module links. */
|
|
13
14
|
export const analyzeJavaScriptSemantics = (source) => {
|
|
@@ -44,7 +45,10 @@ export const analyzeParsedJavaScriptSemantics = (file) => {
|
|
|
44
45
|
references,
|
|
45
46
|
moduleLinks,
|
|
46
47
|
...derived,
|
|
47
|
-
coverage: semanticCoverage(parserPartial
|
|
48
|
+
coverage: semanticCoverage(parserPartial, semanticResourceLimitsIn([
|
|
49
|
+
...bindings.map(({ value }) => value),
|
|
50
|
+
...callables.flatMap((callable) => callable.returnSites.map(({ value }) => value)),
|
|
51
|
+
])),
|
|
48
52
|
limitations: [
|
|
49
53
|
...(parserPartial
|
|
50
54
|
? [
|
|
@@ -59,6 +63,97 @@ export const analyzeParsedJavaScriptSemantics = (file) => {
|
|
|
59
63
|
],
|
|
60
64
|
};
|
|
61
65
|
};
|
|
66
|
+
/**
|
|
67
|
+
* Resolve only the lexical receiver identity needed to distinguish browser
|
|
68
|
+
* `window.open` from XHR and global storage `.open` calls. This deliberately
|
|
69
|
+
* builds definitions without running semantic value or provenance analysis.
|
|
70
|
+
*/
|
|
71
|
+
export const classifyParsedJavaScriptOpenReceivers = (file) => {
|
|
72
|
+
const state = createState(file.program);
|
|
73
|
+
collectDefinitions(file.program, state);
|
|
74
|
+
const facts = new Map();
|
|
75
|
+
traverseJavaScriptAst(file.program, {
|
|
76
|
+
enter: (node) => {
|
|
77
|
+
if ((!t.isCallExpression(node) && !t.isOptionalCallExpression(node)) ||
|
|
78
|
+
(!t.isMemberExpression(node.callee) &&
|
|
79
|
+
!t.isOptionalMemberExpression(node.callee)) ||
|
|
80
|
+
semanticStaticPropertyKey(node.callee.property, node.callee.computed) !== "open" ||
|
|
81
|
+
!t.isIdentifier(node.callee.object))
|
|
82
|
+
return;
|
|
83
|
+
const receiver = node.callee.object.name;
|
|
84
|
+
const binding = resolveSemanticBindingState(state, node, receiver);
|
|
85
|
+
if (binding === undefined) {
|
|
86
|
+
if (semanticResolutionBlocked(state, node, receiver))
|
|
87
|
+
return;
|
|
88
|
+
const fact = openGlobalFact(receiver);
|
|
89
|
+
if (fact !== undefined)
|
|
90
|
+
facts.set(node.start ?? -1, fact);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
// A lexically bound receiver overrides ambient browser globals. Mark an
|
|
94
|
+
// otherwise unresolved local as local so name-based window.open
|
|
95
|
+
// heuristics do not hide its XHR-like overloads.
|
|
96
|
+
facts.set(node.start ?? -1, "local");
|
|
97
|
+
if (receiver === "indexedDB" || receiver === "caches") {
|
|
98
|
+
facts.set(node.start ?? -1, receiver === "indexedDB" ? "local-indexed-db" : "local-cache-storage");
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (binding.mutable || binding.initializers.length !== 1)
|
|
102
|
+
return;
|
|
103
|
+
const initializer = binding.initializers[0]?.node;
|
|
104
|
+
if (!t.isIdentifier(initializer))
|
|
105
|
+
return;
|
|
106
|
+
const initializerBinding = resolveSemanticBindingState(state, initializer, initializer.name);
|
|
107
|
+
if (initializerBinding !== undefined) {
|
|
108
|
+
if (initializer.name === "indexedDB" || initializer.name === "caches") {
|
|
109
|
+
const localFact = initializer.name === "indexedDB"
|
|
110
|
+
? "local-indexed-db"
|
|
111
|
+
: "local-cache-storage";
|
|
112
|
+
facts.set(node.start ?? -1, localFact);
|
|
113
|
+
if (initializerBinding.mutable ||
|
|
114
|
+
initializerBinding.initializers.length !== 1)
|
|
115
|
+
return;
|
|
116
|
+
const nested = initializerBinding.initializers[0]?.node;
|
|
117
|
+
if (t.isIdentifier(nested)) {
|
|
118
|
+
const nestedFact = resolveGlobalAliasFact(state, initializer, nested.name);
|
|
119
|
+
if (nestedFact !== undefined)
|
|
120
|
+
facts.set(node.start ?? -1, nestedFact);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else if (initializer.name === "window") {
|
|
124
|
+
facts.set(node.start ?? -1, "local");
|
|
125
|
+
}
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const aliasFact = resolveGlobalAliasFact(state, initializer, initializer.name);
|
|
129
|
+
if (aliasFact !== undefined)
|
|
130
|
+
facts.set(node.start ?? -1, aliasFact);
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
return facts;
|
|
134
|
+
};
|
|
135
|
+
const openGlobalFact = (name) => {
|
|
136
|
+
if (name === "window" ||
|
|
137
|
+
name === "self" ||
|
|
138
|
+
name === "globalThis" ||
|
|
139
|
+
name === "top" ||
|
|
140
|
+
name === "parent" ||
|
|
141
|
+
name === "opener" ||
|
|
142
|
+
name === "frames" ||
|
|
143
|
+
name === "document")
|
|
144
|
+
return "window";
|
|
145
|
+
if (name === "indexedDB")
|
|
146
|
+
return "indexed-db";
|
|
147
|
+
if (name === "caches")
|
|
148
|
+
return "cache-storage";
|
|
149
|
+
return undefined;
|
|
150
|
+
};
|
|
151
|
+
const resolveGlobalAliasFact = (state, node, name) => {
|
|
152
|
+
if (resolveSemanticBindingState(state, node, name) !== undefined ||
|
|
153
|
+
semanticResolutionBlocked(state, node, name))
|
|
154
|
+
return undefined;
|
|
155
|
+
return openGlobalFact(name);
|
|
156
|
+
};
|
|
62
157
|
const createState = (program) => {
|
|
63
158
|
const root = {
|
|
64
159
|
scopeId: semanticScopeId("program", program),
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
/** Classify whole-file semantic coverage from
|
|
2
|
-
export const semanticCoverage = (parserPartial) =>
|
|
3
|
-
status:
|
|
4
|
-
omittedCount: 0
|
|
5
|
-
|
|
1
|
+
/** Classify whole-file semantic coverage from parsing and value bounds. */
|
|
2
|
+
export const semanticCoverage = (parserPartial, resourceLimits = []) => resourceLimits.length > 0
|
|
3
|
+
? { status: "partial", omittedCount: null, resourceLimits }
|
|
4
|
+
: { status: parserPartial ? "partial" : "complete", omittedCount: 0 };
|
|
5
|
+
/** Read typed resource-limit classifications from any coverage state. */
|
|
6
|
+
export const semanticCoverageResourceLimits = (coverage) => coverage.resourceLimits ?? [];
|
|
6
7
|
/** Classify one callable's direct-return coverage. */
|
|
7
8
|
export const semanticReturnCoverage = (retainedCount, parserPartial) => ({
|
|
8
9
|
status: parserPartial ? "partial" : "complete",
|
|
@@ -3,7 +3,7 @@ import { semanticBuiltinNamespacePath } from "./javascriptSemanticProvenance.js"
|
|
|
3
3
|
import { semanticCallableIdForNode } from "./javascriptSemanticProjection.js";
|
|
4
4
|
import { resolveSemanticBindingState, semanticResolutionBlocked, } from "./javascriptSemanticState.js";
|
|
5
5
|
import { traverseJavaScriptAst } from "./javascriptSemanticTraversal.js";
|
|
6
|
-
import { semanticStaticPropertyKey, semanticStaticPropertyName, } from "./javascriptAstValues.js";
|
|
6
|
+
import { readExactJavaScriptLiteral, semanticStaticPropertyKey, semanticStaticPropertyName, } from "./javascriptAstValues.js";
|
|
7
7
|
/** Resolve bindings written by the nearest variable or assignment owner. */
|
|
8
8
|
export const assignedSemanticResultBindings = (node, ancestors, state) => {
|
|
9
9
|
for (let index = ancestors.length - 1; index >= 0; index -= 1) {
|
|
@@ -164,11 +164,14 @@ export const dataEffectPrimitive = (node) => {
|
|
|
164
164
|
};
|
|
165
165
|
/** Read one static string or expression-free template. */
|
|
166
166
|
export const dataEffectLiteralString = (node) => {
|
|
167
|
-
if (
|
|
168
|
-
return
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
167
|
+
if (node === undefined)
|
|
168
|
+
return null;
|
|
169
|
+
const literal = readExactJavaScriptLiteral(node);
|
|
170
|
+
if (literal.found && typeof literal.value === "string")
|
|
171
|
+
return literal.value;
|
|
172
|
+
return t.isTemplateLiteral(node) && node.expressions.length === 0
|
|
173
|
+
? (node.quasis[0]?.value.raw ?? null)
|
|
174
|
+
: null;
|
|
172
175
|
};
|
|
173
176
|
/** Read a member callee from call or construction syntax. */
|
|
174
177
|
export const dataEffectMemberCallee = (node) => t.isMemberExpression(node.callee) || t.isOptionalMemberExpression(node.callee)
|
|
@@ -179,14 +182,3 @@ export const dataEffectMemberObject = (node) => node !== null &&
|
|
|
179
182
|
(t.isMemberExpression(node) || t.isOptionalMemberExpression(node))
|
|
180
183
|
? node.object
|
|
181
184
|
: null;
|
|
182
|
-
/** Compare Babel source offsets for exact containment. */
|
|
183
|
-
export const containsSemanticNode = (outer, inner) => outer.start !== null &&
|
|
184
|
-
outer.start !== undefined &&
|
|
185
|
-
outer.end !== null &&
|
|
186
|
-
outer.end !== undefined &&
|
|
187
|
-
inner.start !== null &&
|
|
188
|
-
inner.start !== undefined &&
|
|
189
|
-
inner.end !== null &&
|
|
190
|
-
inner.end !== undefined &&
|
|
191
|
-
outer.start <= inner.start &&
|
|
192
|
-
outer.end >= inner.end;
|
|
@@ -3,7 +3,7 @@ import { semanticBuiltinNamespacePath } from "./javascriptSemanticProvenance.js"
|
|
|
3
3
|
import { compareCodePoints } from "../canonicalOrdering.js";
|
|
4
4
|
import { semanticStaticPropertyKey, semanticStaticPropertyName, } from "./javascriptSemanticProjection.js";
|
|
5
5
|
import { resolveSemanticBindingState, semanticResolutionBlocked, } from "./javascriptSemanticState.js";
|
|
6
|
-
import { builtinDataEffectMethod as builtinMethod,
|
|
6
|
+
import { builtinDataEffectMethod as builtinMethod, dataEffectArgumentBindingId as argumentBindingId, dataEffectLiteralString as literalString, dataEffectMemberCallee as memberCallee, dataEffectMemberObject as memberObject, dataEffectPrimitive as primitiveValue, isSemanticProcessObject as isProcessObject, outerDataEffectBinding as outerAssignedBinding, assignedSemanticResultBindings, semanticProjectedBindingFacts, traverseDataEffects as traverseWithContext, } from "./javascriptSemanticDataEffectHelpers.js";
|
|
7
7
|
import { range } from "./javascriptStaticAnalysisHelpers.js";
|
|
8
8
|
/** Recover configuration, request, and boundary candidates from inert syntax. */
|
|
9
9
|
export const collectJavaScriptSemanticDataEffects = (program, state, callables) => {
|
|
@@ -80,20 +80,37 @@ const processConfigurationMember = (node, state) => {
|
|
|
80
80
|
return null;
|
|
81
81
|
// `process.env[""]` names an exact (empty) key; only a dynamic key is unknown.
|
|
82
82
|
const key = semanticStaticPropertyKey(node.property, node.computed);
|
|
83
|
+
if (family === "argv" && key !== null && !isArrayIndexKey(key))
|
|
84
|
+
return null;
|
|
83
85
|
return {
|
|
84
86
|
kind: family === "env" ? "environment" : "argv",
|
|
85
87
|
key,
|
|
86
88
|
resolution: key === null ? "partial" : "complete",
|
|
87
89
|
};
|
|
88
90
|
};
|
|
91
|
+
const isArrayIndexKey = (key) => {
|
|
92
|
+
if (!/^(?:0|[1-9][0-9]*)$/u.test(key))
|
|
93
|
+
return false;
|
|
94
|
+
const index = Number(key);
|
|
95
|
+
return Number.isSafeInteger(index) && index < 2 ** 32 - 1;
|
|
96
|
+
};
|
|
89
97
|
const collectDefaults = (program, context, configurations) => {
|
|
90
98
|
const output = [];
|
|
99
|
+
const configurationsByNode = new Map(configurations.map((candidate) => [candidate.node, candidate]));
|
|
91
100
|
traverseWithContext(program, context, (node) => {
|
|
92
101
|
if (!t.isLogicalExpression(node) ||
|
|
93
102
|
(node.operator !== "??" && node.operator !== "||"))
|
|
94
103
|
return;
|
|
95
|
-
|
|
96
|
-
|
|
104
|
+
let source = node.left;
|
|
105
|
+
while (t.isParenthesizedExpression(source) ||
|
|
106
|
+
t.isTSAsExpression(source) ||
|
|
107
|
+
t.isTSTypeAssertion(source) ||
|
|
108
|
+
t.isTypeCastExpression(source) ||
|
|
109
|
+
t.isTSSatisfiesExpression(source) ||
|
|
110
|
+
t.isTSNonNullExpression(source))
|
|
111
|
+
source = source.expression;
|
|
112
|
+
const candidate = configurationsByNode.get(source);
|
|
113
|
+
if (candidate === undefined)
|
|
97
114
|
return;
|
|
98
115
|
output.push({
|
|
99
116
|
configId: `config:default:${String(node.start ?? -1)}:${String(node.end ?? -1)}`,
|
|
@@ -101,8 +118,8 @@ const collectDefaults = (program, context, configurations) => {
|
|
|
101
118
|
location: range(node.right),
|
|
102
119
|
ownerCallableId: context.callableStack.at(-1) ?? null,
|
|
103
120
|
resultBindingId: outerAssignedBinding(node, context),
|
|
104
|
-
key:
|
|
105
|
-
sourceConfigId:
|
|
121
|
+
key: candidate.operation.key,
|
|
122
|
+
sourceConfigId: candidate.operation.configId,
|
|
106
123
|
value: primitiveValue(node.right),
|
|
107
124
|
resolution: primitiveValue(node.right) === null ? "partial" : "complete",
|
|
108
125
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { canonicalDigest, canonicalJson } from "../comparisonSemantics.js";
|
|
3
3
|
import { compareCodePoints, uniqueSorted } from "../canonicalOrdering.js";
|
|
4
|
+
import { freezeOwnedJsonSnapshotSteps } from "../immutableJson.js";
|
|
4
5
|
import { JAVASCRIPT_SEMANTIC_RELATION_FAMILIES, JAVASCRIPT_SEMANTIC_RELATION_FAMILY, javaScriptSemanticFingerprintInputSchema, javaScriptSemanticFingerprintSchema, javaScriptSemanticGraphInputSchema, javaScriptSemanticGraphRecordSchema, javaScriptSemanticNodeInputSchema, javaScriptSemanticNodeSchema, javaScriptSemanticRelationInputSchema, javaScriptSemanticRelationSchema, javaScriptSemanticUnknownInputSchema, javaScriptSemanticUnknownSchema, } from "./javascriptSemanticGraphSchemas.js";
|
|
5
6
|
const normalizeEvidence = (evidence) => ({
|
|
6
7
|
...evidence,
|
|
@@ -365,3 +366,15 @@ export const createJavaScriptSemanticGraph = (input) => {
|
|
|
365
366
|
throw new z.ZodError(issues);
|
|
366
367
|
return record;
|
|
367
368
|
};
|
|
369
|
+
const validatedImmutableSemanticGraphs = new WeakSet();
|
|
370
|
+
/** Clone and validate synchronously, then return steps to seal the owned graph. */
|
|
371
|
+
export const createImmutableJavaScriptSemanticGraphSteps = (input) => sealValidatedSemanticGraphSteps(createJavaScriptSemanticGraph(input));
|
|
372
|
+
function* sealValidatedSemanticGraphSteps(graph) {
|
|
373
|
+
yield* freezeOwnedJsonSnapshotSteps(graph);
|
|
374
|
+
validatedImmutableSemanticGraphs.add(graph);
|
|
375
|
+
return graph;
|
|
376
|
+
}
|
|
377
|
+
/** Recognize the exact completely sealed graph produced by the owned factory. */
|
|
378
|
+
export const isValidatedImmutableJavaScriptSemanticGraph = (value) => typeof value === "object" &&
|
|
379
|
+
value !== null &&
|
|
380
|
+
validatedImmutableSemanticGraphs.has(value);
|
|
@@ -221,6 +221,7 @@ export const JAVASCRIPT_SEMANTIC_UNKNOWN_REASONS = [
|
|
|
221
221
|
"eval-or-generated-code",
|
|
222
222
|
"incomplete-module",
|
|
223
223
|
"missing-source",
|
|
224
|
+
"resource-limit",
|
|
224
225
|
"unsupported-syntax",
|
|
225
226
|
];
|
|
226
227
|
/** One unresolved semantic frontier before its ID is derived. */
|
|
@@ -1,16 +1,32 @@
|
|
|
1
1
|
import * as t from "@babel/types";
|
|
2
2
|
import { compareCodePoints } from "../canonicalOrdering.js";
|
|
3
3
|
import { semanticPrimitiveKey } from "./javascriptSemanticProvenance.js";
|
|
4
|
+
import { readExactJavaScriptLiteral } from "./javascriptAstValues.js";
|
|
5
|
+
import { SEMANTIC_PRIMITIVE_CANDIDATE_LIMIT, exceedsSemanticPrimitiveStringByteBudget, semanticResourceLimitUnknown, } from "./javascriptSemanticResourceLimits.js";
|
|
6
|
+
/**
|
|
7
|
+
* Keep eight independent binary choices exact, while bounding the next
|
|
8
|
+
* exponential expansion before it allocates hundreds more alternatives.
|
|
9
|
+
*/
|
|
10
|
+
export const MAX_SEMANTIC_PRIMITIVE_CANDIDATES = SEMANTIC_PRIMITIVE_CANDIDATE_LIMIT;
|
|
4
11
|
/** Normalize one bounded collection of possible primitive values. */
|
|
5
12
|
export const semanticPrimitiveSet = (values) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
const uniqueValues = new Set();
|
|
14
|
+
for (const value of values) {
|
|
15
|
+
if (typeof value === "number" && !Number.isFinite(value))
|
|
16
|
+
return {
|
|
17
|
+
status: "unknown",
|
|
18
|
+
reason: "Nonfinite numbers are outside the JSON primitive lattice.",
|
|
19
|
+
};
|
|
20
|
+
uniqueValues.add(value);
|
|
21
|
+
if (uniqueValues.size > MAX_SEMANTIC_PRIMITIVE_CANDIDATES)
|
|
22
|
+
return semanticResourceLimitUnknown("primitive-candidates");
|
|
23
|
+
}
|
|
24
|
+
if (exceedsSemanticPrimitiveStringByteBudget([...uniqueValues].flatMap((value) => typeof value === "string" ? [value] : [])))
|
|
25
|
+
return semanticResourceLimitUnknown("primitive-bytes");
|
|
26
|
+
const unique = [...uniqueValues]
|
|
27
|
+
.map((value) => ({ key: semanticPrimitiveKey(value), value }))
|
|
28
|
+
.sort((left, right) => compareCodePoints(left.key, right.key))
|
|
29
|
+
.map(({ value }) => value);
|
|
14
30
|
const only = unique[0];
|
|
15
31
|
return unique.length === 1 && only !== undefined
|
|
16
32
|
? { status: "literal", value: only }
|
|
@@ -24,13 +40,5 @@ export const semanticPrimitiveCandidates = (value) => value.status === "literal"
|
|
|
24
40
|
: null;
|
|
25
41
|
/** Parse one Babel primitive literal without evaluating code. */
|
|
26
42
|
export const semanticPrimitiveValue = (node) => {
|
|
27
|
-
|
|
28
|
-
return { found: true, value: node.value };
|
|
29
|
-
if (t.isNumericLiteral(node) && Number.isFinite(node.value))
|
|
30
|
-
return { found: true, value: node.value };
|
|
31
|
-
if (t.isBooleanLiteral(node))
|
|
32
|
-
return { found: true, value: node.value };
|
|
33
|
-
if (t.isNullLiteral(node))
|
|
34
|
-
return { found: true, value: null };
|
|
35
|
-
return { found: false };
|
|
43
|
+
return readExactJavaScriptLiteral(node);
|
|
36
44
|
};
|
|
@@ -4,12 +4,16 @@ import { jsonValueSchema } from "../jsonValue.js";
|
|
|
4
4
|
import { digestSchema } from "../digests.js";
|
|
5
5
|
import { prefixedDigestSchema } from "../digests.js";
|
|
6
6
|
const semanticNodeIdSchema = prefixedDigestSchema("jsrg_node");
|
|
7
|
+
const literalValueSchema = jsonValueSchema.refine((value) => value === null ||
|
|
8
|
+
typeof value === "string" ||
|
|
9
|
+
typeof value === "number" ||
|
|
10
|
+
typeof value === "boolean", "Literal seeds accept only JSON primitive values");
|
|
11
|
+
// Zod derivations drop the shared schema's JSON Schema projection override;
|
|
12
|
+
// re-apply it so MCP catalog generation keeps projecting `{}`.
|
|
13
|
+
literalValueSchema._zod.toJSONSchema = () => ({});
|
|
7
14
|
const literalSeedSchema = z.strictObject({
|
|
8
15
|
kind: z.literal("literal"),
|
|
9
|
-
value:
|
|
10
|
-
typeof value === "string" ||
|
|
11
|
-
typeof value === "number" ||
|
|
12
|
-
typeof value === "boolean", "Literal seeds accept only JSON primitive values"),
|
|
16
|
+
value: literalValueSchema,
|
|
13
17
|
});
|
|
14
18
|
/** Authenticated starting points accepted by semantic tracing. */
|
|
15
19
|
export const javaScriptSemanticQuerySeedSchema = z.discriminatedUnion("kind", [
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** Maximum distinct alternatives retained in one normalized primitive value. */
|
|
2
|
+
export const SEMANTIC_PRIMITIVE_CANDIDATE_LIMIT = 256;
|
|
3
|
+
/** Maximum active expression nesting during inert semantic evaluation. */
|
|
4
|
+
export const SEMANTIC_EXPRESSION_DEPTH_LIMIT = 256;
|
|
5
|
+
/** Bound normalized strings and transient keys independently of transport limits. */
|
|
6
|
+
export const SEMANTIC_PRIMITIVE_JSON_BYTES_LIMIT = 1_048_576;
|
|
7
|
+
const RESOURCE_LIMIT_REASON = {
|
|
8
|
+
"primitive-candidates": "Primitive candidate budget exceeded (maximum 256 alternatives).",
|
|
9
|
+
"primitive-bytes": "Primitive string-byte budget exceeded (maximum 1048576 estimated JSON bytes).",
|
|
10
|
+
"expression-depth": "Semantic expression depth budget exceeded (maximum 256 nested expressions).",
|
|
11
|
+
};
|
|
12
|
+
/** Check UTF-16 length against worst-case JSON escaping without flattening. */
|
|
13
|
+
const jsonStringBytesFromLength = (codeUnits) => codeUnits * 6 + 2;
|
|
14
|
+
/** Bound string payload before JSON key serialization or candidate creation. */
|
|
15
|
+
export const exceedsSemanticPrimitiveStringByteBudget = (strings) => {
|
|
16
|
+
let total = 0;
|
|
17
|
+
for (const value of strings) {
|
|
18
|
+
total += jsonStringBytesFromLength(value.length);
|
|
19
|
+
if (total > SEMANTIC_PRIMITIVE_JSON_BYTES_LIMIT)
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
};
|
|
24
|
+
/** Bound all outputs of a primitive addition before concatenating any. */
|
|
25
|
+
export const exceedsSemanticPrimitiveAdditionByteBudget = (left, right) => {
|
|
26
|
+
let total = 0;
|
|
27
|
+
for (const leftValue of left) {
|
|
28
|
+
for (const rightValue of right) {
|
|
29
|
+
if (typeof leftValue !== "string" && typeof rightValue !== "string")
|
|
30
|
+
continue;
|
|
31
|
+
const length = String(leftValue).length + String(rightValue).length;
|
|
32
|
+
total += jsonStringBytesFromLength(length);
|
|
33
|
+
if (total > SEMANTIC_PRIMITIVE_JSON_BYTES_LIMIT)
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
39
|
+
/** Bound template interpolation outputs before creating concatenated strings. */
|
|
40
|
+
export const exceedsSemanticTemplateByteBudget = (prefixes, suffixes) => {
|
|
41
|
+
let total = 0;
|
|
42
|
+
for (const prefix of prefixes) {
|
|
43
|
+
for (const suffix of suffixes) {
|
|
44
|
+
total += jsonStringBytesFromLength(prefix.length + suffix.length);
|
|
45
|
+
if (total > SEMANTIC_PRIMITIVE_JSON_BYTES_LIMIT)
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
};
|
|
51
|
+
/** Make an explicit unknown value tagged with the semantic resource bound. */
|
|
52
|
+
export const semanticResourceLimitUnknown = (resourceLimit) => ({
|
|
53
|
+
status: "unknown",
|
|
54
|
+
reason: RESOURCE_LIMIT_REASON[resourceLimit],
|
|
55
|
+
resourceLimit,
|
|
56
|
+
});
|
|
57
|
+
/** Collect resource-limit classifications from nested semantic values. */
|
|
58
|
+
export const semanticResourceLimitsIn = (values) => {
|
|
59
|
+
const found = new Set();
|
|
60
|
+
const pending = [...values];
|
|
61
|
+
while (pending.length > 0) {
|
|
62
|
+
const value = pending.pop();
|
|
63
|
+
if (value === undefined)
|
|
64
|
+
continue;
|
|
65
|
+
if (value.status === "unknown" && value.resourceLimit !== undefined)
|
|
66
|
+
found.add(value.resourceLimit);
|
|
67
|
+
else if (value.status === "object")
|
|
68
|
+
for (const property of value.properties)
|
|
69
|
+
pending.push(property.value);
|
|
70
|
+
else if (value.status === "array")
|
|
71
|
+
for (const item of value.items)
|
|
72
|
+
pending.push(item);
|
|
73
|
+
}
|
|
74
|
+
return [...found].sort();
|
|
75
|
+
};
|
|
76
|
+
/** Display label for one stable resource classification. */
|
|
77
|
+
export const semanticResourceLimitReason = (resourceLimit) => RESOURCE_LIMIT_REASON[resourceLimit];
|