rea-agents 3.0.0 → 3.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.
Files changed (219) hide show
  1. package/README.md +14 -16
  2. package/dist/application/AnalysisContextQueries.js +21 -9
  3. package/dist/application/ApplicationWorkflowEvidenceResolver.js +19 -11
  4. package/dist/application/ArtifactInventory/policy.js +17 -0
  5. package/dist/application/ArtifactInventory/reader.js +1 -4
  6. package/dist/application/ArtifactInventory/scanCanonical.js +0 -3
  7. package/dist/application/ArtifactInventory/scanReader.js +7 -7
  8. package/dist/application/ArtifactInventory/types.js +1 -5
  9. package/dist/application/BinarySession.js +14 -16
  10. package/dist/application/BinarySessionRecords.js +31 -5
  11. package/dist/application/BinarySessionStatus.js +11 -5
  12. package/dist/application/BrowserEvidence.js +3 -5
  13. package/dist/application/CapabilityClientRequirements.js +26 -0
  14. package/dist/application/CapabilityInventory.js +134 -63
  15. package/dist/application/CrossVersionInventory.js +7 -6
  16. package/dist/application/ElectronActiveEvidence.js +55 -0
  17. package/dist/application/ElectronActiveObservationPort.js +1 -0
  18. package/dist/application/ElectronActiveObservationService.js +81 -0
  19. package/dist/application/EnhancedTools.js +22 -20
  20. package/dist/application/EvidenceBundleCommands.js +5 -1
  21. package/dist/application/EvidenceLedger.js +8 -1
  22. package/dist/application/JavaScriptReplayPermission.js +1 -1
  23. package/dist/application/JavaScriptReplayService.js +23 -15
  24. package/dist/application/ManagedRuntimeCorrelationService.js +9 -5
  25. package/dist/application/NodeRuntimeCharacterizationService.js +8 -9
  26. package/dist/application/ProcessCaptureLifecycle.js +5 -0
  27. package/dist/application/ProcessCli.js +2 -1
  28. package/dist/application/ProcessHarness.js +8 -3
  29. package/dist/application/ProcessNormalization.js +2 -1
  30. package/dist/application/ProjectPermissionStore.js +1 -0
  31. package/dist/application/ReferenceSourceImport.js +2 -2
  32. package/dist/application/SetupClientConfiguration.js +6 -1
  33. package/dist/application/WindowsCapabilities.js +5 -4
  34. package/dist/artifacts/ArtifactProvider.js +8 -10
  35. package/dist/artifacts/SafeOutputTree.js +7 -8
  36. package/dist/browser/CdpCaptureStorageFingerprints.js +10 -7
  37. package/dist/browser/CdpElectronInspection.js +3 -1
  38. package/dist/browser/JavaScriptRuntimeScope.js +5 -0
  39. package/dist/browser/PlaywrightElectronActiveActions.js +324 -0
  40. package/dist/browser/PlaywrightElectronActiveProvider.js +294 -0
  41. package/dist/browser/PlaywrightScenarioBrowser.js +4 -4
  42. package/dist/browser/PlaywrightScenarioSession.js +4 -4
  43. package/dist/browser/SensitiveTextCapture.js +1 -1
  44. package/dist/browser/V8InspectorCaptureProjection.js +1 -0
  45. package/dist/browser/V8InspectorProvider.js +3 -3
  46. package/dist/catalogIdentity.js +12 -6
  47. package/dist/cli/managedCommands.js +1 -1
  48. package/dist/cliApplicationCommands.js +2 -2
  49. package/dist/cliBrowserAdvancedCommands.js +11 -5
  50. package/dist/cliBrowserCommands.js +14 -7
  51. package/dist/cliCommandNames.js +1 -0
  52. package/dist/cliElectronCommands.js +46 -4
  53. package/dist/cliJavaScriptRuntimeCommands.js +14 -6
  54. package/dist/cliObservationOptions.js +4 -0
  55. package/dist/cliPolicyCommands.js +1 -0
  56. package/dist/config/browserScenario.js +77 -0
  57. package/dist/config/electronAutomation.js +35 -0
  58. package/dist/config/environment.js +6 -0
  59. package/dist/config/javascriptReplay.js +41 -0
  60. package/dist/config/managedRuntime.js +25 -0
  61. package/dist/config/parseConfig.js +56 -200
  62. package/dist/config/parsers.js +10 -1
  63. package/dist/config/passiveObservation.js +157 -0
  64. package/dist/config/processCapture.js +47 -0
  65. package/dist/contracts/applicationToolContracts.js +2 -5
  66. package/dist/contracts/applicationWorkflowInputContracts.js +86 -96
  67. package/dist/contracts/artifactToolContracts.js +27 -34
  68. package/dist/contracts/browserToolContracts.js +2 -2
  69. package/dist/contracts/electronToolContracts.js +30 -1
  70. package/dist/contracts/enhancedInputs.js +13 -29
  71. package/dist/contracts/functionWorkflowToolContracts.js +2 -3
  72. package/dist/contracts/managedToolContracts.js +4 -9
  73. package/dist/contracts/managedWorkflowExamples.js +12 -9
  74. package/dist/contracts/managedWorkflowToolContracts.js +30 -27
  75. package/dist/contracts/nativeToolContracts.js +2 -3
  76. package/dist/contracts/sessionToolSchemas.js +61 -0
  77. package/dist/contracts/toolContractExamples.js +1 -0
  78. package/dist/contracts/toolContractHelpers.js +23 -0
  79. package/dist/contracts/toolContracts.js +5 -77
  80. package/dist/contracts/toolEffects.js +15 -0
  81. package/dist/contracts/toolOutputSchemaGroups.js +17 -2
  82. package/dist/contracts/toolOutputSchemaPrimitives.js +76 -26
  83. package/dist/contracts/toolSchemaMetadata.js +128 -0
  84. package/dist/doctorRuntime.js +1 -1
  85. package/dist/domain/androidApplication.js +2 -0
  86. package/dist/domain/appleApplication.js +2 -0
  87. package/dist/domain/binaryTarget.js +7 -5
  88. package/dist/domain/binaryTargetTypes.js +1 -0
  89. package/dist/domain/browserCaptureComparison.js +21 -69
  90. package/dist/domain/browserObservation.js +22 -9
  91. package/dist/domain/bytecodeProvider.js +33 -35
  92. package/dist/domain/callPath.js +3 -2
  93. package/dist/domain/conformanceReplay.js +3 -3
  94. package/dist/domain/conformanceTrustGate.js +151 -16
  95. package/dist/domain/customProtocolCapture.js +3 -3
  96. package/dist/domain/electronActiveObservation.js +277 -0
  97. package/dist/domain/electronObservation.js +15 -11
  98. package/dist/domain/electronStaticAnalysisValues.js +4 -1
  99. package/dist/domain/eventProcessTree.js +82 -79
  100. package/dist/domain/functionComparisonNormalization.js +15 -8
  101. package/dist/domain/functionDossierEvidence.js +9 -4
  102. package/dist/domain/hopperValues.js +68 -71
  103. package/dist/domain/inputIssueProjection.js +4 -1
  104. package/dist/domain/investigationWorkspace.js +16 -15
  105. package/dist/domain/javascriptExportShapeComparisonSchemas.js +2 -2
  106. package/dist/domain/javascriptReplay.js +79 -63
  107. package/dist/domain/javascriptRuntimeObservation.js +1 -0
  108. package/dist/domain/javascriptRuntimeReconciliationActive.js +89 -0
  109. package/dist/domain/javascriptRuntimeReconciliationGraph.js +11 -10
  110. package/dist/domain/javascriptRuntimeReconciliationMatching.js +57 -49
  111. package/dist/domain/javascriptRuntimeReconciliationParsing.js +5 -1
  112. package/dist/domain/javascriptRuntimeReconciliationResult.js +21 -14
  113. package/dist/domain/javascriptRuntimeReconciliationSchemas.js +1 -1
  114. package/dist/domain/knownPageCoverage.js +15 -7
  115. package/dist/domain/nativeApiBoundary.js +15 -7
  116. package/dist/domain/nodeRuntimeCharacterization.js +14 -13
  117. package/dist/domain/processCaptureReactiveValidation.js +8 -3
  118. package/dist/domain/processCaptureValidation.js +7 -3
  119. package/dist/domain/processComparison.js +12 -7
  120. package/dist/domain/processObservation.js +5 -6
  121. package/dist/domain/processReactiveMatching.js +14 -7
  122. package/dist/domain/processReactiveTransition.js +9 -3
  123. package/dist/domain/processScenario.js +6 -3
  124. package/dist/domain/processTraceComparison.js +3 -2
  125. package/dist/domain/protocolCapture.js +8 -6
  126. package/dist/domain/reconstructionReadinessSchemas.js +30 -2
  127. package/dist/domain/referenceSourceImportParsing.js +2 -2
  128. package/dist/domain/replayMachineRuntime.js +5 -3
  129. package/dist/domain/sourceToBundleComparison.js +2 -2
  130. package/dist/domain/sourceToBundleComparisonSchemas.js +8 -8
  131. package/dist/domain/sourceToBundleSignals.js +7 -1
  132. package/dist/domain/staticRuntimeCorrelation.js +7 -5
  133. package/dist/domain/webBundleAnalysis.js +14 -14
  134. package/dist/domain/webCaptureDiff.js +15 -12
  135. package/dist/dotnet/ManagedNativeBoundaryInspector.js +2 -3
  136. package/dist/generatedMcpToolCatalog.js +1 -1
  137. package/dist/generatedPackageMetadata.js +1 -1
  138. package/dist/ghidra/GhidraClient.js +1 -1
  139. package/dist/ghidra/GhidraClientStartup.js +1 -1
  140. package/dist/ghidra/GhidraFunctionValues.js +17 -15
  141. package/dist/ghidra/GhidraInventoryValues.js +57 -47
  142. package/dist/ghidra/GhidraProvider.js +18 -10
  143. package/dist/ghidra/GhidraProviderCapabilities.js +5 -1
  144. package/dist/ghidra/GhidraSocketConnection.js +1 -1
  145. package/dist/ghidra/protocol.js +19 -42
  146. package/dist/hopper/BridgeLauncher.js +3 -1
  147. package/dist/hopper/HopperAnalysisProfile.js +2 -4
  148. package/dist/hopper/HopperCleanup.js +5 -6
  149. package/dist/hopper/HopperClient.js +1 -1
  150. package/dist/hopper/HopperProvider.js +0 -14
  151. package/dist/hopper/LinuxPrivateDisplayProbe.js +16 -10
  152. package/dist/main/reload.js +1 -6
  153. package/dist/main/state.js +0 -14
  154. package/dist/main/transport.js +30 -37
  155. package/dist/main.js +17 -15
  156. package/dist/mcpDoctor.js +2 -24
  157. package/dist/process/PrivateRuntimeRoot.js +17 -0
  158. package/dist/process/ProcessOwnership.js +64 -128
  159. package/dist/process/ProcessOwnershipIdentity.js +13 -0
  160. package/dist/process/ProcessOwnershipObservation.js +88 -0
  161. package/dist/process/ProcessOwnershipProcessTree.js +22 -0
  162. package/dist/process/ProviderDeadline.js +8 -12
  163. package/dist/process/WindowsAuthority.js +32 -0
  164. package/dist/reference/ReferenceSourceReader.js +3 -3
  165. package/dist/reference/ReferenceSourceReaderEntries.js +2 -2
  166. package/dist/replay/JavaScriptReplayWorker.js +95 -11
  167. package/dist/replay/JavaScriptReplayWorkerTypes.js +1 -0
  168. package/dist/replay/LinuxJavaScriptReplayRunner.js +10 -15
  169. package/dist/replay/ReplayOutcome.js +26 -15
  170. package/dist/replay/ReplayWorkerProtocol.js +34 -29
  171. package/dist/server/createServer.js +158 -94
  172. package/dist/server/mcpClientMetadata.js +32 -0
  173. package/dist/server/registerApplicationTools/characterization.js +6 -13
  174. package/dist/server/registerApplicationTools/compareExportShapes.js +2 -7
  175. package/dist/server/registerApplicationTools/compareSourceToBundle.js +2 -7
  176. package/dist/server/registerApplicationTools/compareVersions.js +3 -8
  177. package/dist/server/registerApplicationTools/controlledReplay.js +6 -11
  178. package/dist/server/registerApplicationTools/coverage.js +13 -19
  179. package/dist/server/registerApplicationTools/obligationLedger.js +1 -6
  180. package/dist/server/registerApplicationTools/readiness.js +1 -6
  181. package/dist/server/registerApplicationTools/traceFeature.js +3 -8
  182. package/dist/server/registerApplicationTools/traceSemantics.js +1 -6
  183. package/dist/server/registerArtifactComparisonTool.js +12 -16
  184. package/dist/server/registerBrowserScenarioTool.js +1 -6
  185. package/dist/server/registerBrowserTools.js +37 -79
  186. package/dist/server/registerBundleComparisonTool.js +10 -14
  187. package/dist/server/registerCloseLifecycleTool.js +6 -14
  188. package/dist/server/registerElectronTools.js +30 -47
  189. package/dist/server/registerEnhancedTools.js +114 -122
  190. package/dist/server/registerEvidenceTools.js +5 -9
  191. package/dist/server/registerFunctionComparisonTool.js +11 -15
  192. package/dist/server/registerInvestigationTools.js +41 -57
  193. package/dist/server/registerJavaScriptRuntimeObservationTools.js +13 -27
  194. package/dist/server/registerManagedWorkflowTools/compareManagedMembers.js +4 -9
  195. package/dist/server/registerManagedWorkflowTools/contract.js +2 -3
  196. package/dist/server/registerManagedWorkflowTools/importManagedReconstruction.js +3 -8
  197. package/dist/server/registerManagedWorkflowTools/planManagedRuntimeCorrelation.js +3 -8
  198. package/dist/server/registerManagedWorkflowTools/projectManagedApplicationGraph.js +8 -13
  199. package/dist/server/registerManagedWorkflowTools/verifyManagedNativeBoundaries.js +4 -9
  200. package/dist/server/registerOfficialTools.js +8 -9
  201. package/dist/server/registerProcessComparisonTool.js +19 -24
  202. package/dist/server/registerReplayMachineTool.js +4 -10
  203. package/dist/server/registerSessionRecordTools.js +69 -40
  204. package/dist/server/registerSessionStatusTool.js +13 -28
  205. package/dist/server/registerSessionTools.js +36 -52
  206. package/dist/server/sessionAvailabilityPolicy.js +2 -1
  207. package/dist/server/sessionToolPolicies.js +1 -5
  208. package/dist/server/toolRegistrationOptions.js +4 -192
  209. package/dist/server/toolResult.js +2 -18
  210. package/package.json +22 -14
  211. package/scripts/electron-active-hook-boundaries.cjs +394 -0
  212. package/scripts/electron-active-hook.cjs +501 -0
  213. package/scripts/rea.mjs +1 -11
  214. package/skills/reverse-engineer-anything/SKILL.md +2 -2
  215. package/dist/server/DynamicToolAvailability.js +0 -70
  216. package/dist/server/LazyToolCatalog.js +0 -134
  217. package/dist/server/hydrateServerTools.js +0 -191
  218. package/dist/server/toolInputValidation.js +0 -77
  219. package/scripts/package-runner-bootstrap.mjs +0 -72
@@ -0,0 +1,394 @@
1
+ "use strict";
2
+
3
+ // oxlint-disable-next-line max-lines-per-function -- all adapters must close over one bounded capture context.
4
+ const createElectronActiveBoundaryPatches = ({
5
+ identity,
6
+ patchEmitter,
7
+ processType,
8
+ recordIpc,
9
+ recordRuntime,
10
+ shape,
11
+ }) => {
12
+ const patchedSessions = new WeakSet();
13
+ const patchIpcRenderer = (ipcRenderer) => {
14
+ if (ipcRenderer === null || ipcRenderer === undefined) return;
15
+ for (const [method, kind] of [
16
+ ["send", "ipc-renderer-send"],
17
+ ["sendSync", "ipc-renderer-send"],
18
+ ["invoke", "ipc-renderer-invoke"],
19
+ ["postMessage", "ipc-renderer-post-message"],
20
+ ]) {
21
+ const original = ipcRenderer[method];
22
+ if (typeof original !== "function") continue;
23
+ ipcRenderer[method] = function patchedRendererIpc(channel, ...args) {
24
+ const recorded = recordIpc(kind, channel, args, {
25
+ direction: "renderer-to-main",
26
+ sender: processType(),
27
+ receiver: "main",
28
+ frame: null,
29
+ process_type: processType(),
30
+ error: false,
31
+ });
32
+ try {
33
+ const result = original.call(this, channel, ...args);
34
+ if (result !== null && typeof result?.then === "function")
35
+ return result.then(
36
+ (value) => {
37
+ if (recorded !== null) recorded.result_shape = shape(value);
38
+ return value;
39
+ },
40
+ (cause) => {
41
+ if (recorded !== null) recorded.error = true;
42
+ throw cause;
43
+ },
44
+ );
45
+ if (recorded !== null) recorded.result_shape = shape(result);
46
+ return result;
47
+ } catch (cause) {
48
+ if (recorded !== null) recorded.error = true;
49
+ throw cause;
50
+ }
51
+ };
52
+ }
53
+ };
54
+
55
+ const patchContextBridge = (contextBridge) => {
56
+ if (contextBridge === null || contextBridge === undefined) return;
57
+ for (const method of ["exposeInMainWorld", "exposeInIsolatedWorld"]) {
58
+ const original = contextBridge[method];
59
+ if (typeof original !== "function") continue;
60
+ contextBridge[method] = function patchedContextBridge(...args) {
61
+ const target = typeof args[0] === "string" ? args[0] : null;
62
+ recordRuntime("preload", "context-bridge-exposure", "attempted", {
63
+ target,
64
+ argument_shapes: args.map((value) => shape(value)),
65
+ process_type: processType(),
66
+ });
67
+ try {
68
+ const result = original.apply(this, args);
69
+ recordRuntime("preload", "context-bridge-exposure", "completed", {
70
+ target,
71
+ process_type: processType(),
72
+ });
73
+ return result;
74
+ } catch (cause) {
75
+ recordRuntime("preload", "context-bridge-exposure", "failed", {
76
+ target,
77
+ error: true,
78
+ process_type: processType(),
79
+ });
80
+ throw cause;
81
+ }
82
+ };
83
+ }
84
+ };
85
+
86
+ const patchSession = (session) => {
87
+ if (session === null || session === undefined) return;
88
+ if (
89
+ (typeof session !== "object" && typeof session !== "function") ||
90
+ patchedSessions.has(session)
91
+ )
92
+ return;
93
+ patchedSessions.add(session);
94
+ patchEmitter(session, (event, args) => {
95
+ const kind =
96
+ event === "will-download"
97
+ ? "download"
98
+ : event.includes("certificate") || event.includes("permission")
99
+ ? "permission"
100
+ : event.includes("window") || event.includes("popup")
101
+ ? "popup-attempt"
102
+ : "web-contents-lifecycle";
103
+ if (event === "will-download") {
104
+ const cancel = args[1]?.cancel;
105
+ if (typeof cancel === "function") cancel.call(args[1]);
106
+ }
107
+ recordRuntime(
108
+ kind,
109
+ event,
110
+ event === "will-download" ? "blocked" : "observed",
111
+ {
112
+ target: identity(args[0], "webContents"),
113
+ argument_shapes: args.map((value) => shape(value)),
114
+ error: event === "will-download",
115
+ },
116
+ );
117
+ });
118
+ const originalPermissionRequest = session.setPermissionRequestHandler;
119
+ if (typeof originalPermissionRequest === "function")
120
+ session.setPermissionRequestHandler =
121
+ function blockedPermissionRequest() {
122
+ return originalPermissionRequest.call(
123
+ this,
124
+ (webContents, permission, callback) => {
125
+ recordRuntime("permission", "permission-request", "blocked", {
126
+ target: identity(webContents, "webContents"),
127
+ argument_shapes: [shape(permission)],
128
+ error: true,
129
+ });
130
+ if (typeof callback === "function") callback(false);
131
+ },
132
+ );
133
+ };
134
+ const originalPermissionCheck = session.setPermissionCheckHandler;
135
+ if (typeof originalPermissionCheck === "function")
136
+ session.setPermissionCheckHandler = function blockedPermissionCheck() {
137
+ return originalPermissionCheck.call(this, (webContents, permission) => {
138
+ recordRuntime("permission", "permission-check", "blocked", {
139
+ target: identity(webContents, "webContents"),
140
+ argument_shapes: [shape(permission)],
141
+ error: true,
142
+ });
143
+ return false;
144
+ });
145
+ };
146
+ const originalCertificate = session.setCertificateVerifyProc;
147
+ if (typeof originalCertificate === "function")
148
+ session.setCertificateVerifyProc = function blockedCertificate() {
149
+ return originalCertificate.call(this, (request, callback) => {
150
+ recordRuntime("permission", "certificate-error", "blocked", {
151
+ argument_shapes: [shape(request)],
152
+ error: true,
153
+ });
154
+ if (typeof callback === "function") callback(-2);
155
+ });
156
+ };
157
+ };
158
+
159
+ const patchWindowOpenHandler = (webContents, contentsId) => {
160
+ if (webContents === null || webContents === undefined) return;
161
+ const original = webContents.setWindowOpenHandler;
162
+ if (typeof original !== "function") return;
163
+ const createGuardedHandler =
164
+ (handler) =>
165
+ (...args) => {
166
+ try {
167
+ if (typeof handler === "function") handler(...args);
168
+ } catch {
169
+ recordRuntime("popup-attempt", "window-open-handler", "failed", {
170
+ target: contentsId,
171
+ argument_shapes: args.map((value) => shape(value)),
172
+ error: true,
173
+ });
174
+ return { action: "deny" };
175
+ }
176
+ recordRuntime("popup-attempt", "window-open-handler", "blocked", {
177
+ target: contentsId,
178
+ argument_shapes: args.map((value) => shape(value)),
179
+ error: true,
180
+ });
181
+ return { action: "deny" };
182
+ };
183
+ try {
184
+ original.call(webContents, createGuardedHandler(undefined));
185
+ } catch {
186
+ recordRuntime("popup-attempt", "window-open-handler-install", "failed", {
187
+ target: contentsId,
188
+ error: true,
189
+ });
190
+ }
191
+ webContents.setWindowOpenHandler = function blockedWindowOpenHandler(
192
+ handler,
193
+ ) {
194
+ return original.call(this, createGuardedHandler(handler));
195
+ };
196
+ };
197
+
198
+ const patchSessionManager = (sessionModule) => {
199
+ if (sessionModule === null || sessionModule === undefined) return;
200
+ patchSession(sessionModule.defaultSession);
201
+ for (const method of ["fromPartition", "fromPath"]) {
202
+ const original = sessionModule[method];
203
+ if (typeof original !== "function") continue;
204
+ sessionModule[method] = function patchedSessionFactory(...args) {
205
+ const session = original.apply(this, args);
206
+ patchSession(session);
207
+ return session;
208
+ };
209
+ }
210
+ };
211
+
212
+ const patchApplicationEffects = (app) => {
213
+ if (app === null || app === undefined) return;
214
+ for (const method of [
215
+ "relaunch",
216
+ "setAsDefaultProtocolClient",
217
+ "setLoginItemSettings",
218
+ ]) {
219
+ const original = app[method];
220
+ if (typeof original !== "function") continue;
221
+ app[method] = function blockedApplicationEffect(...args) {
222
+ recordRuntime(
223
+ method === "relaunch" ? "updater" : "protocol",
224
+ method,
225
+ "blocked",
226
+ { argument_shapes: args.map((value) => shape(value)), error: true },
227
+ );
228
+ return method === "setAsDefaultProtocolClient" ? false : undefined;
229
+ };
230
+ }
231
+ };
232
+
233
+ const patchNativeAddonLoading = () => {
234
+ const original = process.dlopen;
235
+ if (typeof original !== "function") return;
236
+ process.dlopen = function patchedDlopen(module, filename, ...args) {
237
+ let digest = null;
238
+ try {
239
+ const fs = require("node:fs");
240
+ const crypto = require("node:crypto");
241
+ const stat = fs.statSync(filename);
242
+ if (stat.isFile() && stat.size <= 16 * 1024 * 1024)
243
+ digest = crypto
244
+ .createHash("sha256")
245
+ .update(fs.readFileSync(filename))
246
+ .digest("hex");
247
+ } catch {
248
+ digest = null;
249
+ }
250
+ recordRuntime("native-addon", "dlopen", "attempted", {
251
+ artifact_path: typeof filename === "string" ? filename : null,
252
+ artifact_sha256: digest,
253
+ argument_shapes: [
254
+ shape(module),
255
+ shape(filename),
256
+ ...args.map((value) => shape(value)),
257
+ ],
258
+ });
259
+ try {
260
+ const result = original.call(this, module, filename, ...args);
261
+ recordRuntime("native-addon", "dlopen", "completed", {
262
+ artifact_path: typeof filename === "string" ? filename : null,
263
+ artifact_sha256: digest,
264
+ });
265
+ return result;
266
+ } catch (cause) {
267
+ recordRuntime("native-addon", "dlopen", "failed", {
268
+ artifact_path: typeof filename === "string" ? filename : null,
269
+ artifact_sha256: digest,
270
+ error: true,
271
+ });
272
+ throw cause;
273
+ }
274
+ };
275
+ };
276
+
277
+ const patchUtilityProcess = (utilityProcess) => {
278
+ if (utilityProcess === null || utilityProcess === undefined) return;
279
+ const original = utilityProcess.fork;
280
+ if (typeof original !== "function") return;
281
+ utilityProcess.fork = function patchedFork(...args) {
282
+ recordRuntime("process-lifecycle", "utility-process-fork", "attempted", {
283
+ argument_shapes: args.map((value) => shape(value)),
284
+ process_type: "main",
285
+ });
286
+ const child = original.apply(this, args);
287
+ const childId = identity(child, "utility");
288
+ recordRuntime("process-lifecycle", "utility-process-fork", "completed", {
289
+ target: childId,
290
+ process_type: "main",
291
+ });
292
+ patchEmitter(child, (event, eventArgs) => {
293
+ if (event === "message") {
294
+ recordIpc("ipc-utility-to-main", null, eventArgs, {
295
+ direction: "utility-to-main",
296
+ sender: childId,
297
+ receiver: "main",
298
+ target: childId,
299
+ process_type: "main",
300
+ error: false,
301
+ });
302
+ return;
303
+ }
304
+ recordRuntime("process-lifecycle", `utility.${event}`, "observed", {
305
+ target: childId,
306
+ process_type: "utility",
307
+ argument_shapes: eventArgs.map((value) => shape(value)),
308
+ });
309
+ });
310
+ if (child && typeof child.postMessage === "function") {
311
+ const postMessage = child.postMessage.bind(child);
312
+ child.postMessage = (...messageArgs) => {
313
+ const recorded = recordIpc(
314
+ "utility-process-message",
315
+ null,
316
+ messageArgs,
317
+ {
318
+ direction: "main-to-utility",
319
+ sender: "main",
320
+ receiver: childId,
321
+ target: childId,
322
+ process_type: "main",
323
+ error: false,
324
+ },
325
+ );
326
+ try {
327
+ const result = postMessage(...messageArgs);
328
+ if (recorded !== null) recorded.result_shape = shape(result);
329
+ return result;
330
+ } catch (cause) {
331
+ if (recorded !== null) recorded.error = true;
332
+ throw cause;
333
+ }
334
+ };
335
+ }
336
+ return child;
337
+ };
338
+ };
339
+
340
+ const patchShell = (shell) => {
341
+ if (shell === null || shell === undefined) return;
342
+ for (const method of ["openExternal", "openPath"]) {
343
+ const original = shell[method];
344
+ if (typeof original !== "function") continue;
345
+ shell[method] = function blockedShellCall(...args) {
346
+ recordRuntime("shell-attempt", method, "blocked", {
347
+ argument_shapes: args.map((value) => shape(value)),
348
+ error: true,
349
+ });
350
+ return Promise.reject(new Error("External shell effects are blocked"));
351
+ };
352
+ }
353
+ };
354
+
355
+ const patchChildProcess = () => {
356
+ const childProcess = require("node:child_process");
357
+ for (const method of ["spawn", "fork", "exec", "execFile"]) {
358
+ const original = childProcess[method];
359
+ if (typeof original !== "function") continue;
360
+ childProcess[method] = function patchedChildProcess(...args) {
361
+ recordRuntime("process-lifecycle", `child.${method}`, "attempted", {
362
+ argument_shapes: args.map((value) => shape(value)),
363
+ });
364
+ const child = original.apply(this, args);
365
+ const childId = identity(child, "child");
366
+ recordRuntime("process-lifecycle", `child.${method}`, "completed", {
367
+ target: childId,
368
+ });
369
+ patchEmitter(child, (event, eventArgs) =>
370
+ recordRuntime("process-lifecycle", `child.${event}`, "observed", {
371
+ target: childId,
372
+ argument_shapes: eventArgs.map((value) => shape(value)),
373
+ }),
374
+ );
375
+ return child;
376
+ };
377
+ }
378
+ };
379
+
380
+ return {
381
+ patchApplicationEffects,
382
+ patchChildProcess,
383
+ patchContextBridge,
384
+ patchIpcRenderer,
385
+ patchNativeAddonLoading,
386
+ patchSession,
387
+ patchSessionManager,
388
+ patchShell,
389
+ patchWindowOpenHandler,
390
+ patchUtilityProcess,
391
+ };
392
+ };
393
+
394
+ module.exports = { createElectronActiveBoundaryPatches };