rea-agents 2.0.0 → 2.2.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 +103 -38
- package/bridge/ghidra/ReaGhidraBridge.java +96 -11
- package/dist/application/AndroidApplicationService.js +17 -0
- package/dist/application/AppleApplicationService.js +17 -0
- 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 +24 -2
- package/dist/application/ClientRegistrationStatus.js +11 -4
- package/dist/application/CrossVersionInventory.js +8 -2
- package/dist/application/CrossVersionInvestigation.js +1 -23
- package/dist/application/CrossVersionInvestigationCollections.js +23 -0
- package/dist/application/DirectAnalysis.js +47 -44
- package/dist/application/Doctor.js +156 -238
- package/dist/application/DoctorDiagnostics.js +180 -0
- package/dist/application/ElectronBoundaryAnalysis.js +23 -7
- package/dist/application/ElectronBoundaryGraphWindows.js +32 -8
- package/dist/application/EnhancedToolPagination.js +22 -0
- package/dist/application/EnhancedToolTypes.js +4 -0
- package/dist/application/EnhancedTools.js +20 -37
- package/dist/application/InstrumentedJavaScriptReplayHost.js +36 -0
- package/dist/application/InventoryProjectionEvidence.js +41 -0
- package/dist/application/InvestigationProviders.js +12 -0
- package/dist/application/InvestigationWorkspaceStore.js +24 -10
- package/dist/application/JavaScriptArtifactAnalysis.js +45 -6
- package/dist/application/JavaScriptArtifactFiles.js +6 -2
- package/dist/application/JavaScriptArtifactGraphBuilder.js +23 -1
- package/dist/application/JavaScriptArtifactGraphBundlers.js +225 -0
- package/dist/application/JavaScriptArtifactGraphContext.js +37 -36
- package/dist/application/JavaScriptArtifactGraphDocuments.js +27 -4
- 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 +1 -1
- package/dist/application/JavaScriptJsonModules.js +39 -0
- package/dist/application/JavaScriptModuleRelationships.js +262 -0
- package/dist/application/JavaScriptReplayPermission.js +16 -0
- package/dist/application/JavaScriptReplayService.js +182 -156
- package/dist/application/LinuxHopper.js +10 -0
- package/dist/application/MacHopper.js +22 -11
- 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/ProcessPairedExperiment.js +72 -0
- package/dist/application/ProjectPermissionStore.js +48 -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 +148 -260
- package/dist/application/SetupClientConfiguration.js +224 -0
- package/dist/application/SetupClients.js +24 -2
- package/dist/application/SetupPlan.js +124 -12
- package/dist/application/SetupSkill.js +54 -36
- package/dist/application/SupportedClients.js +1 -0
- package/dist/application/Uninstall.js +12 -3
- package/dist/application/Upgrade.js +16 -1
- package/dist/application/WindowsCapabilities.js +86 -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 +29 -496
- package/dist/browser/CdpObservationSession.js +51 -8
- package/dist/browser/CdpPageCapture.js +12 -133
- 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 +4 -0
- 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 +113 -0
- package/dist/cli/types.js +1 -0
- package/dist/cli/utilityCommands.js +122 -0
- package/dist/cli.js +10 -768
- package/dist/cliApplicationCommands.js +118 -4
- package/dist/cliBrowserAdvancedCommands.js +73 -16
- package/dist/cliBrowserCommands.js +39 -115
- package/dist/cliCommandNames.js +4 -0
- package/dist/cliElectronCommands.js +33 -62
- package/dist/cliEvidenceCommands.js +13 -2
- package/dist/cliInvestigationCommands.js +53 -10
- package/dist/cliObservationOptions.js +137 -0
- package/dist/cliPolicyCommands.js +80 -46
- package/dist/cliSetup.js +306 -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 -375
- package/dist/contracts/applicationToolContracts.js +134 -0
- package/dist/contracts/electronToolContracts.js +51 -3
- package/dist/contracts/managedToolContracts.js +8 -3
- package/dist/contracts/managedWorkflowToolContracts.js +3 -3
- package/dist/contracts/providerSelection.js +2 -0
- package/dist/contracts/sessionStatusContract.js +26 -0
- package/dist/contracts/toolContractTypes.js +12 -1
- package/dist/contracts/toolContracts.js +5 -12
- package/dist/contracts/toolEffects.js +14 -0
- package/dist/contracts/toolOutputSchemaGroups.js +274 -0
- package/dist/contracts/toolOutputSchemaPrimitives.js +328 -0
- package/dist/contracts/toolOutputSchemas.js +2 -550
- package/dist/domain/analysisErrorPresentation.js +234 -0
- package/dist/domain/analysisErrorProjection.js +284 -0
- package/dist/domain/androidApplication.js +206 -0
- package/dist/domain/appleApplication.js +221 -0
- package/dist/domain/artifactComparison.js +34 -15
- package/dist/domain/binaryTarget.js +87 -37
- package/dist/domain/boundedCartesianProjection.js +15 -0
- package/dist/domain/browserObservation.js +1 -285
- package/dist/domain/browserObservationSchemas.js +286 -0
- package/dist/domain/electronStaticAnalysisBrowser.js +14 -2
- package/dist/domain/errors.js +4 -486
- package/dist/domain/functionComparison.js +4 -165
- package/dist/domain/functionComparisonDimensions.js +164 -0
- package/dist/domain/javascriptApplicationVersionItems.js +18 -6
- package/dist/domain/javascriptApplicationVersionKeys.js +8 -8
- package/dist/domain/javascriptExportInstrumentation.js +97 -0
- package/dist/domain/javascriptFeatureTraversal.js +19 -7
- package/dist/domain/javascriptRuntimeStaticCandidates.js +3 -1
- 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 +5 -221
- package/dist/domain/javascriptStaticAnalysisBundler.js +209 -0
- package/dist/domain/javascriptStaticAnalysisCalls.js +180 -0
- package/dist/domain/javascriptStaticAnalysisHelpers.js +71 -2
- package/dist/domain/knownPageCoverage.js +21 -0
- package/dist/domain/managedApplicationGraph.js +14 -364
- 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 +16 -8
- package/dist/domain/managedMemberComparison.js +37 -391
- package/dist/domain/managedMemberComparisonCoverage.js +72 -0
- package/dist/domain/managedMemberComparisonMatch.js +356 -0
- package/dist/domain/managedNativeVerification.js +27 -389
- package/dist/domain/managedNativeVerificationMatch.js +272 -0
- package/dist/domain/managedNativeVerificationSchemas.js +141 -0
- package/dist/domain/managedReconstruction.js +82 -69
- package/dist/domain/managedRuntimeCorrelation.js +12 -3
- package/dist/domain/nodeRuntimeCharacterization.js +66 -0
- package/dist/domain/permissionPolicy.js +2 -0
- package/dist/domain/processComparison.js +19 -0
- package/dist/domain/processPairedExperiment.js +128 -0
- package/dist/domain/reconstructionCoverage.js +387 -0
- package/dist/domain/reconstructionCoverageEvaluation.js +212 -0
- package/dist/domain/reconstructionVerificationSchemas.js +8 -0
- package/dist/domain/replayMachine.js +316 -0
- package/dist/domain/replayMachineRuntime.js +215 -0
- package/dist/domain/runtimeCharacterization.js +85 -0
- package/dist/domain/runtimeIdentification.js +210 -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 +50 -29
- package/dist/dotnet/ManagedMemberInspector.js +51 -785
- package/dist/dotnet/ManagedMemberInspectorCore.js +297 -0
- package/dist/dotnet/ManagedMemberInstructionDecoder.js +427 -0
- package/dist/dotnet/ManagedMemberRows.js +120 -0
- package/dist/dotnet/ManagedMetadataInventory.js +42 -306
- package/dist/dotnet/ManagedMetadataInventoryRows.js +292 -0
- package/dist/dotnet/ManagedMetadataLayout.js +48 -111
- 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 +102 -350
- package/dist/dotnet/ManagedPeReader.js +59 -28
- package/dist/evaluation/CodexAgentEval.js +132 -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 +61 -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 +4 -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 -146
- 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 +64 -50
- package/dist/replay/LinuxJavaScriptReplayRunner.js +173 -390
- package/dist/replay/LinuxJavaScriptReplaySandbox.js +140 -0
- package/dist/replay/ReplayOutcome.js +95 -0
- package/dist/replay/ReplayProcessLifecycle.js +71 -0
- package/dist/server/ProcessCaptureElicitation.js +157 -0
- package/dist/server/createServer.js +124 -56
- package/dist/server/javascriptApplicationResult.js +85 -0
- 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 +10 -112
- package/dist/server/registerBrowserTools.js +59 -83
- package/dist/server/registerElectronTools.js +48 -49
- package/dist/server/registerEnhancedTools.js +34 -42
- package/dist/server/registerEvidenceResources.js +56 -0
- package/dist/server/registerInvestigationTools/helpers.js +74 -0
- package/dist/server/registerInvestigationTools/types.js +1 -0
- package/dist/server/registerInvestigationTools.js +83 -116
- package/dist/server/registerJavaScriptApplicationGraphResource.js +69 -0
- package/dist/server/registerManagedTools.js +18 -1
- 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 +10 -274
- package/dist/server/registerOfficialTools.js +73 -59
- package/dist/server/registerSessionRecordTools.js +137 -0
- package/dist/server/registerSessionStatusTool.js +97 -26
- package/dist/server/registerSessionTools.js +60 -164
- package/dist/server/sessionAvailabilityPolicy.js +10 -0
- package/dist/server/toolRegistrationOptions.js +101 -3
- package/dist/server/toolResult.js +15 -4
- package/package.json +11 -11
- package/skills/reverse-engineer-anything/SKILL.md +76 -0
- package/skills/reverse-engineer-anything/references/controlled-replay.md +12 -0
- package/skills/reverse-engineer-anything/references/evidence-workflows.md +33 -0
- package/skills/reverse-engineer-anything/references/javascript-applications.md +25 -0
- package/skills/reverse-engineer-anything/references/native-and-artifacts.md +36 -0
- package/skills/reverse-engineer-anything/references/runtime-observation.md +24 -0
- package/scripts/prepare-node-pty.mjs +0 -35
- package/scripts/rebuild-native.mjs +0 -22
- package/skills/rea-analysis/SKILL.md +0 -222
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { readEvidenceBundle, writeEvidenceBundle, } from "../application/EvidenceBundleFiles.js";
|
|
2
|
+
import { exportEvidenceBundleInputSchema, importEvidenceBundleInputSchema, listUnknownsInputSchema, SESSION_TOOL_CONTRACTS, verifyUnknownResolutionInputSchema, } from "../contracts/toolContracts.js";
|
|
3
|
+
import { AnalysisProtocolError, PermissionRequiredError, } from "../domain/errors.js";
|
|
4
|
+
import { recordUnknownInputSchema, updateUnknownInputSchema, } from "../domain/residualUnknown.js";
|
|
5
|
+
import { err, ok } from "../domain/result.js";
|
|
6
|
+
import { safeParseToolInput } from "./toolInputValidation.js";
|
|
7
|
+
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
|
8
|
+
import { toCallToolResult } from "./toolResult.js";
|
|
9
|
+
/** Register evidence bundle import and export tools. */
|
|
10
|
+
export const registerEvidenceTools = (registration) => {
|
|
11
|
+
registerExportEvidenceTool(registration);
|
|
12
|
+
registerImportEvidenceTool(registration);
|
|
13
|
+
};
|
|
14
|
+
const registerExportEvidenceTool = ({ server, session, exportContract, filePolicy, permissionAuthority, }) => {
|
|
15
|
+
server.registerTool(exportContract.name, toolRegistrationOptions(exportContract), async (input) => {
|
|
16
|
+
const parsedInput = safeParseToolInput(exportEvidenceBundleInputSchema, input, exportContract.name);
|
|
17
|
+
if (!parsedInput.ok)
|
|
18
|
+
return toCallToolResult(parsedInput, exportContract);
|
|
19
|
+
const parsed = parsedInput.value;
|
|
20
|
+
const bundle = session.exportEvidenceBundle();
|
|
21
|
+
if (parsed.path === undefined)
|
|
22
|
+
return toCallToolResult(ok(bundle), exportContract);
|
|
23
|
+
const denied = await authorizeEvidencePath({
|
|
24
|
+
authority: permissionAuthority,
|
|
25
|
+
capability: "evidence_write",
|
|
26
|
+
path: parsed.path,
|
|
27
|
+
access: "write",
|
|
28
|
+
operationIdentity: `export_evidence:${parsed.path}`,
|
|
29
|
+
});
|
|
30
|
+
if (denied !== undefined)
|
|
31
|
+
return toCallToolResult(denied, exportContract);
|
|
32
|
+
const written = await writeEvidenceBundle(bundle, parsed.path, parsed.overwrite, filePolicy);
|
|
33
|
+
return written.ok
|
|
34
|
+
? toCallToolResult(ok({
|
|
35
|
+
path: written.value.path,
|
|
36
|
+
bytes: written.value.bytes,
|
|
37
|
+
records: bundle.records.length,
|
|
38
|
+
}), exportContract)
|
|
39
|
+
: toCallToolResult(written, exportContract);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
const registerImportEvidenceTool = ({ server, session, importContract, filePolicy, permissionAuthority, }) => {
|
|
43
|
+
server.registerTool(importContract.name, toolRegistrationOptions(importContract), async (input) => {
|
|
44
|
+
const parsedInput = safeParseToolInput(importEvidenceBundleInputSchema, input, importContract.name);
|
|
45
|
+
if (!parsedInput.ok)
|
|
46
|
+
return toCallToolResult(parsedInput, importContract);
|
|
47
|
+
const path = parsedInput.value.path;
|
|
48
|
+
const denied = await authorizeEvidencePath({
|
|
49
|
+
authority: permissionAuthority,
|
|
50
|
+
capability: "evidence_read",
|
|
51
|
+
path,
|
|
52
|
+
access: "read",
|
|
53
|
+
operationIdentity: `import_evidence:${path}`,
|
|
54
|
+
});
|
|
55
|
+
if (denied !== undefined)
|
|
56
|
+
return toCallToolResult(denied, importContract);
|
|
57
|
+
const loaded = await readEvidenceBundle(path, filePolicy);
|
|
58
|
+
if (!loaded.ok)
|
|
59
|
+
return toCallToolResult(loaded, importContract);
|
|
60
|
+
const imported = session.importEvidenceBundle(loaded.value);
|
|
61
|
+
if (imported.ok && imported.value > 0)
|
|
62
|
+
server.sendResourceListChanged();
|
|
63
|
+
return imported.ok
|
|
64
|
+
? toCallToolResult(ok({
|
|
65
|
+
imported: imported.value,
|
|
66
|
+
total: session.exportEvidenceBundle().records.length,
|
|
67
|
+
}), importContract)
|
|
68
|
+
: toCallToolResult(imported, importContract);
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const authorizeEvidencePath = async (input) => {
|
|
72
|
+
if (input.authority === undefined)
|
|
73
|
+
return undefined;
|
|
74
|
+
const authorized = await input.authority.authorize({
|
|
75
|
+
capability: input.capability,
|
|
76
|
+
roots: [input.path],
|
|
77
|
+
executables: [],
|
|
78
|
+
environment_names: [],
|
|
79
|
+
network: "none",
|
|
80
|
+
mount: false,
|
|
81
|
+
operation_identity: input.operationIdentity,
|
|
82
|
+
}, input.access);
|
|
83
|
+
return authorized.ok ? undefined : permissionFailure(authorized);
|
|
84
|
+
};
|
|
85
|
+
/** Register residual-unknown query and mutation tools. */
|
|
86
|
+
export const registerUnknownTools = ({ server, session, contracts, }) => {
|
|
87
|
+
const listContract = contracts[14];
|
|
88
|
+
const recordContract = contracts[15];
|
|
89
|
+
const updateContract = contracts[16];
|
|
90
|
+
const verifyContract = contracts[17];
|
|
91
|
+
server.registerTool(listContract.name, toolRegistrationOptions(listContract), (input) => {
|
|
92
|
+
const parsed = safeParseToolInput(listUnknownsInputSchema, input, listContract.name);
|
|
93
|
+
if (!parsed.ok)
|
|
94
|
+
return toCallToolResult(parsed, listContract);
|
|
95
|
+
const filters = parsed.value;
|
|
96
|
+
return toCallToolResult(ok(session.listUnknowns({
|
|
97
|
+
...(filters.status === undefined ? {} : { status: filters.status }),
|
|
98
|
+
...(filters.severity === undefined
|
|
99
|
+
? {}
|
|
100
|
+
: { severity: filters.severity }),
|
|
101
|
+
...(filters.domain === undefined ? {} : { domain: filters.domain }),
|
|
102
|
+
})), listContract);
|
|
103
|
+
});
|
|
104
|
+
server.registerTool(recordContract.name, toolRegistrationOptions(recordContract), (input) => {
|
|
105
|
+
const parsed = safeParseToolInput(recordUnknownInputSchema, input, recordContract.name);
|
|
106
|
+
if (!parsed.ok)
|
|
107
|
+
return toCallToolResult(parsed, recordContract);
|
|
108
|
+
const result = session.recordUnknown(parsed.value);
|
|
109
|
+
if (result.ok)
|
|
110
|
+
server.sendResourceListChanged();
|
|
111
|
+
return toCallToolResult(result, recordContract);
|
|
112
|
+
});
|
|
113
|
+
server.registerTool(updateContract.name, toolRegistrationOptions(updateContract), (input) => {
|
|
114
|
+
const parsed = safeParseToolInput(updateUnknownInputSchema, input, updateContract.name);
|
|
115
|
+
if (!parsed.ok)
|
|
116
|
+
return toCallToolResult(parsed, updateContract);
|
|
117
|
+
const result = session.updateUnknown(parsed.value);
|
|
118
|
+
if (result.ok)
|
|
119
|
+
server.sendResourceListChanged();
|
|
120
|
+
return toCallToolResult(result, updateContract);
|
|
121
|
+
});
|
|
122
|
+
server.registerTool(verifyContract.name, toolRegistrationOptions(verifyContract), (input) => {
|
|
123
|
+
const parsed = safeParseToolInput(verifyUnknownResolutionInputSchema, input, verifyContract.name);
|
|
124
|
+
return parsed.ok
|
|
125
|
+
? toCallToolResult(session.verifyUnknownResolution(parsed.value.unknown_id), verifyContract)
|
|
126
|
+
: toCallToolResult(parsed, verifyContract);
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
const permissionFailure = (failure) => {
|
|
130
|
+
if (failure.ok)
|
|
131
|
+
return err(new AnalysisProtocolError("Expected a denied permission"));
|
|
132
|
+
return err(failure.error instanceof PermissionRequiredError
|
|
133
|
+
? failure.error
|
|
134
|
+
: new AnalysisProtocolError(failure.error.message, {
|
|
135
|
+
cause: failure.error,
|
|
136
|
+
}));
|
|
137
|
+
};
|
|
@@ -6,7 +6,8 @@ import { buildCapabilityInventory } from "../application/CapabilityInventory.js"
|
|
|
6
6
|
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
|
7
7
|
import { safeParseToolInput } from "./toolInputValidation.js";
|
|
8
8
|
/** Register the read-only provider and target status operation. */
|
|
9
|
-
export const registerSessionStatusTool = (
|
|
9
|
+
export const registerSessionStatusTool = (options) => {
|
|
10
|
+
const { server, session, contract, startedAt, availabilityPolicy } = options;
|
|
10
11
|
server.registerTool(contract.name, toolRegistrationOptions(contract), (input) => {
|
|
11
12
|
const parsedInput = safeParseToolInput(binarySessionInputSchema, input, contract.name);
|
|
12
13
|
if (!parsedInput.ok)
|
|
@@ -15,38 +16,108 @@ export const registerSessionStatusTool = (server, session, contract, startedAt,
|
|
|
15
16
|
const client = server.server.getClientVersion();
|
|
16
17
|
const clientCapabilities = server.server.getClientCapabilities();
|
|
17
18
|
const status = session.status();
|
|
19
|
+
const statusObject = jsonObjectSchema.parse(status);
|
|
20
|
+
const toolAvailability = buildCapabilityInventory(status, availabilityPolicy());
|
|
21
|
+
const serverIdentity = createServerIdentity({
|
|
22
|
+
startedAt,
|
|
23
|
+
expected: {
|
|
24
|
+
...(parsed.expected_package_version === undefined
|
|
25
|
+
? {}
|
|
26
|
+
: { package_version: parsed.expected_package_version }),
|
|
27
|
+
...(parsed.expected_catalog_digest === undefined
|
|
28
|
+
? {}
|
|
29
|
+
: { catalog_digest: parsed.expected_catalog_digest }),
|
|
30
|
+
...(parsed.expected_server_path === undefined
|
|
31
|
+
? {}
|
|
32
|
+
: { server_path: parsed.expected_server_path }),
|
|
33
|
+
},
|
|
34
|
+
...(client === undefined ? {} : { client }),
|
|
35
|
+
...(server.server.getNegotiatedProtocolVersion() === undefined
|
|
36
|
+
? {}
|
|
37
|
+
: {
|
|
38
|
+
protocolVersion: server.server.getNegotiatedProtocolVersion(),
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
18
41
|
return toCallToolResult({
|
|
19
42
|
ok: true,
|
|
20
|
-
value: {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
43
|
+
value: projectSessionStatus({
|
|
44
|
+
input: parsed,
|
|
45
|
+
status: statusObject,
|
|
46
|
+
toolAvailability,
|
|
47
|
+
serverIdentity,
|
|
48
|
+
clientFeatures: {
|
|
24
49
|
elicitation_form: clientCapabilities?.elicitation?.form !== undefined,
|
|
25
50
|
elicitation_url: clientCapabilities?.elicitation?.url !== undefined,
|
|
26
51
|
roots: clientCapabilities?.roots !== undefined,
|
|
27
52
|
sampling: clientCapabilities?.sampling !== undefined,
|
|
28
53
|
},
|
|
29
|
-
|
|
30
|
-
startedAt,
|
|
31
|
-
expected: {
|
|
32
|
-
...(parsed.expected_package_version === undefined
|
|
33
|
-
? {}
|
|
34
|
-
: { package_version: parsed.expected_package_version }),
|
|
35
|
-
...(parsed.expected_catalog_digest === undefined
|
|
36
|
-
? {}
|
|
37
|
-
: { catalog_digest: parsed.expected_catalog_digest }),
|
|
38
|
-
...(parsed.expected_server_path === undefined
|
|
39
|
-
? {}
|
|
40
|
-
: { server_path: parsed.expected_server_path }),
|
|
41
|
-
},
|
|
42
|
-
...(client === undefined ? {} : { client }),
|
|
43
|
-
...(server.server.getNegotiatedProtocolVersion() === undefined
|
|
44
|
-
? {}
|
|
45
|
-
: {
|
|
46
|
-
protocolVersion: server.server.getNegotiatedProtocolVersion(),
|
|
47
|
-
}),
|
|
48
|
-
}),
|
|
49
|
-
},
|
|
54
|
+
}),
|
|
50
55
|
}, contract);
|
|
51
56
|
});
|
|
52
57
|
};
|
|
58
|
+
const projectSessionStatus = (options) => {
|
|
59
|
+
if (options.input.detail === "full")
|
|
60
|
+
return jsonObjectSchema.parse({
|
|
61
|
+
view: "full",
|
|
62
|
+
...options.status,
|
|
63
|
+
tool_availability: options.toolAvailability,
|
|
64
|
+
client_features: options.clientFeatures,
|
|
65
|
+
server_identity: options.serverIdentity,
|
|
66
|
+
});
|
|
67
|
+
const open = options.status.open === true;
|
|
68
|
+
const activeProvider = activeProviderFrom(options.status);
|
|
69
|
+
if (options.input.detail === "capabilities") {
|
|
70
|
+
const filtered = options.input.capability_family === undefined
|
|
71
|
+
? options.toolAvailability
|
|
72
|
+
: options.toolAvailability.filter(({ surface }) => surface === options.input.capability_family);
|
|
73
|
+
const items = filtered.slice(options.input.cursor, options.input.cursor + options.input.limit);
|
|
74
|
+
const nextCursor = options.input.cursor + items.length;
|
|
75
|
+
return jsonObjectSchema.parse({
|
|
76
|
+
view: "capabilities",
|
|
77
|
+
open,
|
|
78
|
+
provider: options.status.provider,
|
|
79
|
+
active_provider: activeProvider,
|
|
80
|
+
capability_family: options.input.capability_family ?? null,
|
|
81
|
+
capabilities: {
|
|
82
|
+
items,
|
|
83
|
+
cursor: options.input.cursor,
|
|
84
|
+
limit: options.input.limit,
|
|
85
|
+
total: filtered.length,
|
|
86
|
+
next_cursor: nextCursor < filtered.length ? nextCursor : null,
|
|
87
|
+
has_more: nextCursor < filtered.length,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return jsonObjectSchema.parse({
|
|
92
|
+
view: "summary",
|
|
93
|
+
open,
|
|
94
|
+
provider: options.status.provider,
|
|
95
|
+
active_provider: activeProvider,
|
|
96
|
+
target: open ? targetFrom(options.status) : null,
|
|
97
|
+
alignment: options.serverIdentity.alignment,
|
|
98
|
+
recommended_actions: recommendedActions(open, options.serverIdentity.alignment.state),
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
const activeProviderFrom = (status) => {
|
|
102
|
+
const binding = jsonObjectSchema.safeParse(status.analysis_provider_binding);
|
|
103
|
+
return binding.success ? (binding.data.provider ?? null) : null;
|
|
104
|
+
};
|
|
105
|
+
const targetFrom = (status) => ({
|
|
106
|
+
path: status.path,
|
|
107
|
+
format: status.format,
|
|
108
|
+
kind: status.kind,
|
|
109
|
+
sha256: status.sha256,
|
|
110
|
+
architecture: status.architecture ?? null,
|
|
111
|
+
});
|
|
112
|
+
const recommendedActions = (open, alignment) => [
|
|
113
|
+
...(alignment === "mcp_server_restart_required"
|
|
114
|
+
? ["Restart the registered MCP server or client before continuing."]
|
|
115
|
+
: []),
|
|
116
|
+
...(!open
|
|
117
|
+
? [
|
|
118
|
+
"Route the supplied target directly: ASAR/JavaScript to analyze_javascript_application, packages to inventory_artifact, managed PE/CLI to inspect_managed_artifact, browser/Electron runtimes to their list-target tools, and native binaries to open_binary.",
|
|
119
|
+
]
|
|
120
|
+
: [
|
|
121
|
+
"Continue from the active target with binary_overview or a bounded target-specific query.",
|
|
122
|
+
]),
|
|
123
|
+
];
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { SESSION_TOOL_CONTRACTS } from "../contracts/toolContracts.js";
|
|
3
3
|
import { toCallToolResult } from "./toolResult.js";
|
|
4
4
|
import { logToolExecution } from "./toolLogging.js";
|
|
5
5
|
import { err, ok } from "../domain/result.js";
|
|
6
6
|
import { processScenarioSchema } from "../domain/processCapture.js";
|
|
7
7
|
import { captureProcessScenario } from "../application/ProcessHarness.js";
|
|
8
|
-
import {
|
|
9
|
-
import { readEvidenceBundle, writeEvidenceBundle, } from "../application/EvidenceBundleFiles.js";
|
|
8
|
+
import { processCapturePermissionRequest } from "../application/ProcessCapturePermission.js";
|
|
10
9
|
import { readAnalysisSnapshot, writeAnalysisSnapshot, } from "../application/AnalysisSnapshotFiles.js";
|
|
11
10
|
import { AnalysisProtocolError, PermissionRequiredError, UnknownRegistryError, } from "../domain/errors.js";
|
|
12
11
|
import { DENY_EVIDENCE_FILE_POLICY, DENY_PROCESS_POLICY, } from "./sessionToolPolicies.js";
|
|
@@ -21,6 +20,10 @@ import { registerInvestigationTools } from "./registerInvestigationTools.js";
|
|
|
21
20
|
import { closeBinaryInputSchema, openBinaryInputSchema, } from "../contracts/sessionLifecycleInputs.js";
|
|
22
21
|
import { registerSessionStatusTool } from "./registerSessionStatusTool.js";
|
|
23
22
|
import { mcpProgressReporter } from "./mcpProgress.js";
|
|
23
|
+
import { authorizeProcessCaptureWithElicitation, } from "./ProcessCaptureElicitation.js";
|
|
24
|
+
import { isInputRequiredResult } from "@modelcontextprotocol/server";
|
|
25
|
+
import { registerEvidenceTools, registerUnknownTools, } from "./registerSessionRecordTools.js";
|
|
26
|
+
import { sessionAvailabilityPolicy } from "./sessionAvailabilityPolicy.js";
|
|
24
27
|
const permissionFailure = (failure) => {
|
|
25
28
|
if (failure.ok)
|
|
26
29
|
return err(new AnalysisProtocolError("Expected a denied permission"));
|
|
@@ -59,25 +62,19 @@ const recordProcessResidualUnknowns = (session, scenario, evidence, residuals) =
|
|
|
59
62
|
}
|
|
60
63
|
return ok(null);
|
|
61
64
|
};
|
|
62
|
-
const registerProcessTools = ({ server, session, logger, processPolicy, captureContract, permissionAuthority, }) => {
|
|
65
|
+
const registerProcessTools = ({ server, session, logger, processPolicy, captureContract, permissionAuthority, processCaptureElicitation, }) => {
|
|
63
66
|
server.registerTool(captureContract.name, toolRegistrationOptions(captureContract), async (input, context) => {
|
|
64
67
|
const parsedInput = safeParseToolInput(processScenarioSchema, input, captureContract.name);
|
|
65
68
|
if (!parsedInput.ok)
|
|
66
69
|
return toCallToolResult(parsedInput, captureContract);
|
|
67
70
|
const scenario = parsedInput.value;
|
|
68
71
|
if (permissionAuthority !== undefined) {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
...scenario.inherit_environment,
|
|
76
|
-
],
|
|
77
|
-
network: scenario.network_access === "host" ? "external" : "none",
|
|
78
|
-
mount: false,
|
|
79
|
-
operation_identity: `capture_process_scenario:${scenario.executable}`,
|
|
80
|
-
}, "read");
|
|
72
|
+
const request = processCapturePermissionRequest(scenario);
|
|
73
|
+
const authorized = processCaptureElicitation === undefined
|
|
74
|
+
? await permissionAuthority.authorize(request, "read")
|
|
75
|
+
: await authorizeProcessCaptureWithElicitation(permissionAuthority, request, context, processCaptureElicitation);
|
|
76
|
+
if (isInputRequiredResult(authorized))
|
|
77
|
+
return authorized;
|
|
81
78
|
if (!authorized.ok)
|
|
82
79
|
return toCallToolResult(permissionFailure(authorized), captureContract);
|
|
83
80
|
}
|
|
@@ -108,111 +105,19 @@ const registerProcessTools = ({ server, session, logger, processPolicy, captureC
|
|
|
108
105
|
return toCallToolResult(ok(evidence), captureContract);
|
|
109
106
|
});
|
|
110
107
|
};
|
|
111
|
-
const
|
|
112
|
-
server
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const authorized = await permissionAuthority.authorize({
|
|
122
|
-
capability: "evidence_write",
|
|
123
|
-
roots: [parsed.path],
|
|
124
|
-
executables: [],
|
|
125
|
-
environment_names: [],
|
|
126
|
-
network: "none",
|
|
127
|
-
mount: false,
|
|
128
|
-
operation_identity: `export_evidence:${parsed.path}`,
|
|
129
|
-
}, "write");
|
|
130
|
-
if (!authorized.ok)
|
|
131
|
-
return toCallToolResult(permissionFailure(authorized), exportContract);
|
|
132
|
-
}
|
|
133
|
-
const written = await writeEvidenceBundle(bundle, parsed.path, parsed.overwrite, filePolicy);
|
|
134
|
-
return written.ok
|
|
135
|
-
? toCallToolResult(ok({
|
|
136
|
-
path: written.value.path,
|
|
137
|
-
bytes: written.value.bytes,
|
|
138
|
-
records: bundle.records.length,
|
|
139
|
-
}), exportContract)
|
|
140
|
-
: toCallToolResult(written, exportContract);
|
|
141
|
-
});
|
|
142
|
-
server.registerTool(importContract.name, toolRegistrationOptions(importContract), async (input) => {
|
|
143
|
-
const parsedInput = safeParseToolInput(importEvidenceBundleInputSchema, input, importContract.name);
|
|
144
|
-
if (!parsedInput.ok)
|
|
145
|
-
return toCallToolResult(parsedInput, importContract);
|
|
146
|
-
const path = parsedInput.value.path;
|
|
147
|
-
if (permissionAuthority !== undefined) {
|
|
148
|
-
const authorized = await permissionAuthority.authorize({
|
|
149
|
-
capability: "evidence_read",
|
|
150
|
-
roots: [path],
|
|
151
|
-
executables: [],
|
|
152
|
-
environment_names: [],
|
|
153
|
-
network: "none",
|
|
154
|
-
mount: false,
|
|
155
|
-
operation_identity: `import_evidence:${path}`,
|
|
156
|
-
}, "read");
|
|
157
|
-
if (!authorized.ok)
|
|
158
|
-
return toCallToolResult(permissionFailure(authorized), importContract);
|
|
159
|
-
}
|
|
160
|
-
const loaded = await readEvidenceBundle(path, filePolicy);
|
|
161
|
-
if (!loaded.ok)
|
|
162
|
-
return toCallToolResult(loaded, importContract);
|
|
163
|
-
const imported = session.importEvidenceBundle(loaded.value);
|
|
164
|
-
if (imported.ok && imported.value > 0)
|
|
165
|
-
server.sendResourceListChanged();
|
|
166
|
-
return imported.ok
|
|
167
|
-
? toCallToolResult(ok({
|
|
168
|
-
imported: imported.value,
|
|
169
|
-
total: session.exportEvidenceBundle().records.length,
|
|
170
|
-
}), importContract)
|
|
171
|
-
: toCallToolResult(imported, importContract);
|
|
172
|
-
});
|
|
173
|
-
};
|
|
174
|
-
const registerUnknownTools = ({ server, session, contracts: [listContract, recordContract, updateContract, verifyContract], }) => {
|
|
175
|
-
server.registerTool(listContract.name, toolRegistrationOptions(listContract), (input) => {
|
|
176
|
-
const parsedInput = safeParseToolInput(listUnknownsInputSchema, input, listContract.name);
|
|
177
|
-
if (!parsedInput.ok)
|
|
178
|
-
return toCallToolResult(parsedInput, listContract);
|
|
179
|
-
const filters = parsedInput.value;
|
|
180
|
-
return toCallToolResult(ok(session.listUnknowns({
|
|
181
|
-
...(filters.status === undefined ? {} : { status: filters.status }),
|
|
182
|
-
...(filters.severity === undefined
|
|
183
|
-
? {}
|
|
184
|
-
: { severity: filters.severity }),
|
|
185
|
-
...(filters.domain === undefined ? {} : { domain: filters.domain }),
|
|
186
|
-
})), listContract);
|
|
187
|
-
});
|
|
188
|
-
server.registerTool(recordContract.name, toolRegistrationOptions(recordContract), (input) => {
|
|
189
|
-
const parsedInput = safeParseToolInput(recordUnknownInputSchema, input, recordContract.name);
|
|
190
|
-
if (!parsedInput.ok)
|
|
191
|
-
return toCallToolResult(parsedInput, recordContract);
|
|
192
|
-
const recorded = session.recordUnknown(parsedInput.value);
|
|
193
|
-
if (recorded.ok)
|
|
194
|
-
server.sendResourceListChanged();
|
|
195
|
-
return toCallToolResult(recorded, recordContract);
|
|
196
|
-
});
|
|
197
|
-
server.registerTool(updateContract.name, toolRegistrationOptions(updateContract), (input) => {
|
|
198
|
-
const parsedInput = safeParseToolInput(updateUnknownInputSchema, input, updateContract.name);
|
|
199
|
-
if (!parsedInput.ok)
|
|
200
|
-
return toCallToolResult(parsedInput, updateContract);
|
|
201
|
-
const updated = session.updateUnknown(parsedInput.value);
|
|
202
|
-
if (updated.ok)
|
|
203
|
-
server.sendResourceListChanged();
|
|
204
|
-
return toCallToolResult(updated, updateContract);
|
|
205
|
-
});
|
|
206
|
-
server.registerTool(verifyContract.name, toolRegistrationOptions(verifyContract), (input) => {
|
|
207
|
-
const parsedInput = safeParseToolInput(verifyUnknownResolutionInputSchema, input, verifyContract.name);
|
|
208
|
-
if (!parsedInput.ok)
|
|
209
|
-
return toCallToolResult(parsedInput, verifyContract);
|
|
210
|
-
const unknownId = parsedInput.value.unknown_id;
|
|
211
|
-
return toCallToolResult(session.verifyUnknownResolution(unknownId), verifyContract);
|
|
108
|
+
const registerLifecycleTools = (registration) => {
|
|
109
|
+
const { server, session, contracts, startedAt, availabilityPolicy } = registration;
|
|
110
|
+
registerOpenLifecycleTool(registration);
|
|
111
|
+
registerCloseLifecycleTool(registration);
|
|
112
|
+
registerSessionStatusTool({
|
|
113
|
+
server,
|
|
114
|
+
session,
|
|
115
|
+
contract: contracts[2],
|
|
116
|
+
startedAt,
|
|
117
|
+
availabilityPolicy,
|
|
212
118
|
});
|
|
213
119
|
};
|
|
214
|
-
const
|
|
215
|
-
const [openContract, closeContract, statusContract] = contracts;
|
|
120
|
+
const registerOpenLifecycleTool = ({ server, session, logger, contracts: [openContract], snapshotFilePolicy, permissionAuthority, }) => {
|
|
216
121
|
server.registerTool(openContract.name, toolRegistrationOptions(openContract), async (input, context) => {
|
|
217
122
|
const parsedInput = safeParseToolInput(openBinaryInputSchema, input, openContract.name);
|
|
218
123
|
if (!parsedInput.ok)
|
|
@@ -263,54 +168,55 @@ const registerLifecycleTools = ({ server, session, logger, contracts, snapshotFi
|
|
|
263
168
|
}, openContract)
|
|
264
169
|
: toCallToolResult(opened, openContract);
|
|
265
170
|
});
|
|
171
|
+
};
|
|
172
|
+
const registerCloseLifecycleTool = ({ server, session, logger, contracts: [, closeContract], snapshotFilePolicy, permissionAuthority, }) => {
|
|
266
173
|
server.registerTool(closeContract.name, toolRegistrationOptions(closeContract), async (input) => {
|
|
267
174
|
const parsedInput = safeParseToolInput(closeBinaryInputSchema, input, closeContract.name);
|
|
268
175
|
if (!parsedInput.ok)
|
|
269
176
|
return toCallToolResult(parsedInput, closeContract);
|
|
270
177
|
const parsed = parsedInput.value;
|
|
271
|
-
if (parsed.snapshot_path
|
|
272
|
-
if (permissionAuthority !== undefined) {
|
|
273
|
-
const authorized = await permissionAuthority.authorize({
|
|
274
|
-
capability: "snapshot_write",
|
|
275
|
-
roots: [parsed.snapshot_path],
|
|
276
|
-
executables: [],
|
|
277
|
-
environment_names: [],
|
|
278
|
-
network: "none",
|
|
279
|
-
mount: false,
|
|
280
|
-
operation_identity: `close_binary:snapshot:${parsed.snapshot_path}`,
|
|
281
|
-
}, "write");
|
|
282
|
-
if (!authorized.ok)
|
|
283
|
-
return toCallToolResult(permissionFailure(authorized), closeContract);
|
|
284
|
-
}
|
|
285
|
-
const snapshot = session.exportAnalysisSnapshot();
|
|
286
|
-
if (!snapshot.ok)
|
|
287
|
-
return toCallToolResult(snapshot, closeContract);
|
|
288
|
-
const written = await writeAnalysisSnapshot(snapshot.value, parsed.snapshot_path, parsed.overwrite, snapshotFilePolicy);
|
|
289
|
-
if (!written.ok)
|
|
290
|
-
return toCallToolResult(written, closeContract);
|
|
178
|
+
if (parsed.snapshot_path === undefined) {
|
|
291
179
|
const closed = await logToolExecution(logger, closeContract.name, () => session.close());
|
|
292
180
|
if (closed.ok)
|
|
293
181
|
server.sendToolListChanged();
|
|
294
|
-
return closed
|
|
295
|
-
? toCallToolResult(ok({
|
|
296
|
-
path: written.value.path,
|
|
297
|
-
bytes: written.value.bytes,
|
|
298
|
-
entries: snapshot.value.entries.length,
|
|
299
|
-
}), closeContract)
|
|
300
|
-
: toCallToolResult(closed, closeContract);
|
|
182
|
+
return toCallToolResult(closed, closeContract);
|
|
301
183
|
}
|
|
184
|
+
if (permissionAuthority !== undefined) {
|
|
185
|
+
const authorized = await permissionAuthority.authorize({
|
|
186
|
+
capability: "snapshot_write",
|
|
187
|
+
roots: [parsed.snapshot_path],
|
|
188
|
+
executables: [],
|
|
189
|
+
environment_names: [],
|
|
190
|
+
network: "none",
|
|
191
|
+
mount: false,
|
|
192
|
+
operation_identity: `close_binary:snapshot:${parsed.snapshot_path}`,
|
|
193
|
+
}, "write");
|
|
194
|
+
if (!authorized.ok)
|
|
195
|
+
return toCallToolResult(permissionFailure(authorized), closeContract);
|
|
196
|
+
}
|
|
197
|
+
const snapshot = session.exportAnalysisSnapshot();
|
|
198
|
+
if (!snapshot.ok)
|
|
199
|
+
return toCallToolResult(snapshot, closeContract);
|
|
200
|
+
const written = await writeAnalysisSnapshot(snapshot.value, parsed.snapshot_path, parsed.overwrite, snapshotFilePolicy);
|
|
201
|
+
if (!written.ok)
|
|
202
|
+
return toCallToolResult(written, closeContract);
|
|
302
203
|
const closed = await logToolExecution(logger, closeContract.name, () => session.close());
|
|
303
204
|
if (closed.ok)
|
|
304
205
|
server.sendToolListChanged();
|
|
305
|
-
return
|
|
206
|
+
return closed.ok
|
|
207
|
+
? toCallToolResult(ok({
|
|
208
|
+
path: written.value.path,
|
|
209
|
+
bytes: written.value.bytes,
|
|
210
|
+
entries: snapshot.value.entries.length,
|
|
211
|
+
}), closeContract)
|
|
212
|
+
: toCallToolResult(closed, closeContract);
|
|
306
213
|
});
|
|
307
|
-
registerSessionStatusTool(server, session, statusContract, startedAt, availabilityPolicy);
|
|
308
214
|
};
|
|
309
215
|
export const registerSessionTools = (server, session, logger, options = {}) => {
|
|
310
216
|
const processPolicy = options.processPolicy ?? DENY_PROCESS_POLICY;
|
|
311
217
|
const evidenceFilePolicy = options.evidenceFilePolicy ?? DENY_EVIDENCE_FILE_POLICY;
|
|
312
218
|
const analysisSnapshotFilePolicy = options.analysisSnapshotFilePolicy ?? DENY_EVIDENCE_FILE_POLICY;
|
|
313
|
-
const [openContract, closeContract, statusContract, exportContract, importContract, captureContract, compareContract, compareArtifactsContract, compareFunctionsContract, compareBundlesContract, changedBehaviorContract, callPathContract, staticRuntimeContract, reconstructionContract,
|
|
219
|
+
const [openContract, closeContract, statusContract, exportContract, importContract, captureContract, compareContract, compareArtifactsContract, compareFunctionsContract, compareBundlesContract, changedBehaviorContract, callPathContract, staticRuntimeContract, reconstructionContract,] = SESSION_TOOL_CONTRACTS;
|
|
314
220
|
registerLifecycleTools({
|
|
315
221
|
server,
|
|
316
222
|
session,
|
|
@@ -318,15 +224,7 @@ export const registerSessionTools = (server, session, logger, options = {}) => {
|
|
|
318
224
|
contracts: [openContract, closeContract, statusContract],
|
|
319
225
|
snapshotFilePolicy: analysisSnapshotFilePolicy,
|
|
320
226
|
startedAt: options.startedAt ?? new Date().toISOString(),
|
|
321
|
-
availabilityPolicy: options.availabilityPolicy
|
|
322
|
-
(() => ({
|
|
323
|
-
processCaptureEnabled: processPolicy.enabled,
|
|
324
|
-
evidenceFileRoots: evidenceFilePolicy.roots.length,
|
|
325
|
-
browserObservationEnabled: false,
|
|
326
|
-
electronObservationEnabled: false,
|
|
327
|
-
javascriptReplayEnabled: false,
|
|
328
|
-
managedRuntimeEnabled: false,
|
|
329
|
-
})),
|
|
227
|
+
availabilityPolicy: sessionAvailabilityPolicy(options.availabilityPolicy, processPolicy, evidenceFilePolicy),
|
|
330
228
|
...(options.permissionAuthority === undefined
|
|
331
229
|
? {}
|
|
332
230
|
: { permissionAuthority: options.permissionAuthority }),
|
|
@@ -350,6 +248,9 @@ export const registerSessionTools = (server, session, logger, options = {}) => {
|
|
|
350
248
|
...(options.permissionAuthority === undefined
|
|
351
249
|
? {}
|
|
352
250
|
: { permissionAuthority: options.permissionAuthority }),
|
|
251
|
+
...(options.processCaptureElicitation === undefined
|
|
252
|
+
? {}
|
|
253
|
+
: { processCaptureElicitation: options.processCaptureElicitation }),
|
|
353
254
|
});
|
|
354
255
|
registerProcessComparisonTool(server, session, compareContract);
|
|
355
256
|
registerArtifactComparisonTool(server, session, compareArtifactsContract);
|
|
@@ -376,11 +277,6 @@ export const registerSessionTools = (server, session, logger, options = {}) => {
|
|
|
376
277
|
registerUnknownTools({
|
|
377
278
|
server,
|
|
378
279
|
session,
|
|
379
|
-
contracts:
|
|
380
|
-
listUnknownContract,
|
|
381
|
-
recordUnknownContract,
|
|
382
|
-
updateUnknownContract,
|
|
383
|
-
verifyUnknownContract,
|
|
384
|
-
],
|
|
280
|
+
contracts: SESSION_TOOL_CONTRACTS,
|
|
385
281
|
});
|
|
386
282
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Select configured availability reporting or the target-free defaults. */
|
|
2
|
+
export const sessionAvailabilityPolicy = (configured, processPolicy, evidenceFilePolicy) => configured ??
|
|
3
|
+
(() => ({
|
|
4
|
+
processCaptureEnabled: processPolicy.enabled,
|
|
5
|
+
evidenceFileRoots: evidenceFilePolicy.roots.length,
|
|
6
|
+
browserObservationEnabled: false,
|
|
7
|
+
electronObservationEnabled: false,
|
|
8
|
+
javascriptReplayEnabled: false,
|
|
9
|
+
managedRuntimeEnabled: false,
|
|
10
|
+
}));
|