superbased 1.4.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 (343) hide show
  1. package/LICENSE +31 -0
  2. package/README.md +84 -0
  3. package/SUPERBASED_SKILL.md +358 -0
  4. package/dist/electron/ai/ai-client.d.ts +45 -0
  5. package/dist/electron/ai/ai-client.d.ts.map +1 -0
  6. package/dist/electron/ai/ai-client.js +205 -0
  7. package/dist/electron/ai/ai-client.js.map +1 -0
  8. package/dist/electron/ai/context-builder.d.ts +8 -0
  9. package/dist/electron/ai/context-builder.d.ts.map +1 -0
  10. package/dist/electron/ai/context-builder.js +28 -0
  11. package/dist/electron/ai/context-builder.js.map +1 -0
  12. package/dist/electron/ai/instruction-parser.d.ts +11 -0
  13. package/dist/electron/ai/instruction-parser.d.ts.map +1 -0
  14. package/dist/electron/ai/instruction-parser.js +47 -0
  15. package/dist/electron/ai/instruction-parser.js.map +1 -0
  16. package/dist/electron/ai/orchestrator.d.ts +17 -0
  17. package/dist/electron/ai/orchestrator.d.ts.map +1 -0
  18. package/dist/electron/ai/orchestrator.js +53 -0
  19. package/dist/electron/ai/orchestrator.js.map +1 -0
  20. package/dist/electron/ai/providers/anthropic.d.ts +6 -0
  21. package/dist/electron/ai/providers/anthropic.d.ts.map +1 -0
  22. package/dist/electron/ai/providers/anthropic.js +67 -0
  23. package/dist/electron/ai/providers/anthropic.js.map +1 -0
  24. package/dist/electron/ai/providers/azure-openai.d.ts +12 -0
  25. package/dist/electron/ai/providers/azure-openai.d.ts.map +1 -0
  26. package/dist/electron/ai/providers/azure-openai.js +87 -0
  27. package/dist/electron/ai/providers/azure-openai.js.map +1 -0
  28. package/dist/electron/ai/providers/gemini.d.ts +6 -0
  29. package/dist/electron/ai/providers/gemini.d.ts.map +1 -0
  30. package/dist/electron/ai/providers/gemini.js +49 -0
  31. package/dist/electron/ai/providers/gemini.js.map +1 -0
  32. package/dist/electron/ai/providers/openai.d.ts +6 -0
  33. package/dist/electron/ai/providers/openai.d.ts.map +1 -0
  34. package/dist/electron/ai/providers/openai.js +68 -0
  35. package/dist/electron/ai/providers/openai.js.map +1 -0
  36. package/dist/electron/core/auth-store.d.ts +15 -0
  37. package/dist/electron/core/auth-store.d.ts.map +1 -0
  38. package/dist/electron/core/auth-store.js +86 -0
  39. package/dist/electron/core/auth-store.js.map +1 -0
  40. package/dist/electron/core/config.d.ts +6 -0
  41. package/dist/electron/core/config.d.ts.map +1 -0
  42. package/dist/electron/core/config.js +81 -0
  43. package/dist/electron/core/config.js.map +1 -0
  44. package/dist/electron/core/file-logger.d.ts +17 -0
  45. package/dist/electron/core/file-logger.d.ts.map +1 -0
  46. package/dist/electron/core/file-logger.js +74 -0
  47. package/dist/electron/core/file-logger.js.map +1 -0
  48. package/dist/electron/core/json-store.d.ts +4 -0
  49. package/dist/electron/core/json-store.d.ts.map +1 -0
  50. package/dist/electron/core/json-store.js +118 -0
  51. package/dist/electron/core/json-store.js.map +1 -0
  52. package/dist/electron/core/paths.d.ts +17 -0
  53. package/dist/electron/core/paths.d.ts.map +1 -0
  54. package/dist/electron/core/paths.js +117 -0
  55. package/dist/electron/core/paths.js.map +1 -0
  56. package/dist/electron/core/platform.d.ts +21 -0
  57. package/dist/electron/core/platform.d.ts.map +1 -0
  58. package/dist/electron/core/platform.js +18 -0
  59. package/dist/electron/core/platform.js.map +1 -0
  60. package/dist/electron/core/process-coord.d.ts +19 -0
  61. package/dist/electron/core/process-coord.d.ts.map +1 -0
  62. package/dist/electron/core/process-coord.js +124 -0
  63. package/dist/electron/core/process-coord.js.map +1 -0
  64. package/dist/electron/db/database.d.ts +154 -0
  65. package/dist/electron/db/database.d.ts.map +1 -0
  66. package/dist/electron/db/database.js +637 -0
  67. package/dist/electron/db/database.js.map +1 -0
  68. package/dist/electron/db/models.d.ts +26 -0
  69. package/dist/electron/db/models.d.ts.map +1 -0
  70. package/dist/electron/db/models.js +4 -0
  71. package/dist/electron/db/models.js.map +1 -0
  72. package/dist/electron/logger.d.ts +9 -0
  73. package/dist/electron/logger.d.ts.map +1 -0
  74. package/dist/electron/logger.js +18 -0
  75. package/dist/electron/logger.js.map +1 -0
  76. package/dist/electron/main.js +3286 -0
  77. package/dist/electron/modules/active-window.d.ts +6 -0
  78. package/dist/electron/modules/active-window.d.ts.map +1 -0
  79. package/dist/electron/modules/active-window.js +68 -0
  80. package/dist/electron/modules/active-window.js.map +1 -0
  81. package/dist/electron/modules/api-server.d.ts +8 -0
  82. package/dist/electron/modules/api-server.d.ts.map +1 -0
  83. package/dist/electron/modules/api-server.js +1324 -0
  84. package/dist/electron/modules/api-server.js.map +1 -0
  85. package/dist/electron/modules/auth.d.ts +28 -0
  86. package/dist/electron/modules/auth.d.ts.map +1 -0
  87. package/dist/electron/modules/auth.js +150 -0
  88. package/dist/electron/modules/auth.js.map +1 -0
  89. package/dist/electron/modules/azure-speech-realtime.d.ts +38 -0
  90. package/dist/electron/modules/azure-speech-realtime.d.ts.map +1 -0
  91. package/dist/electron/modules/azure-speech-realtime.js +354 -0
  92. package/dist/electron/modules/azure-speech-realtime.js.map +1 -0
  93. package/dist/electron/modules/capture-modes.d.ts +19 -0
  94. package/dist/electron/modules/capture-modes.d.ts.map +1 -0
  95. package/dist/electron/modules/capture-modes.js +100 -0
  96. package/dist/electron/modules/capture-modes.js.map +1 -0
  97. package/dist/electron/modules/capture.d.ts +16 -0
  98. package/dist/electron/modules/capture.d.ts.map +1 -0
  99. package/dist/electron/modules/capture.js +139 -0
  100. package/dist/electron/modules/capture.js.map +1 -0
  101. package/dist/electron/modules/clipboard.d.ts +6 -0
  102. package/dist/electron/modules/clipboard.d.ts.map +1 -0
  103. package/dist/electron/modules/clipboard.js +26 -0
  104. package/dist/electron/modules/clipboard.js.map +1 -0
  105. package/dist/electron/modules/color-picker.d.ts +4 -0
  106. package/dist/electron/modules/color-picker.d.ts.map +1 -0
  107. package/dist/electron/modules/color-picker.js +233 -0
  108. package/dist/electron/modules/color-picker.js.map +1 -0
  109. package/dist/electron/modules/dictation.d.ts +25 -0
  110. package/dist/electron/modules/dictation.d.ts.map +1 -0
  111. package/dist/electron/modules/dictation.js +1058 -0
  112. package/dist/electron/modules/dictation.js.map +1 -0
  113. package/dist/electron/modules/error-reporter.d.ts +7 -0
  114. package/dist/electron/modules/error-reporter.d.ts.map +1 -0
  115. package/dist/electron/modules/error-reporter.js +65 -0
  116. package/dist/electron/modules/error-reporter.js.map +1 -0
  117. package/dist/electron/modules/hotkeys.d.ts +4 -0
  118. package/dist/electron/modules/hotkeys.d.ts.map +1 -0
  119. package/dist/electron/modules/hotkeys.js +40 -0
  120. package/dist/electron/modules/hotkeys.js.map +1 -0
  121. package/dist/electron/modules/keystroke.d.ts +7 -0
  122. package/dist/electron/modules/keystroke.d.ts.map +1 -0
  123. package/dist/electron/modules/keystroke.js +53 -0
  124. package/dist/electron/modules/keystroke.js.map +1 -0
  125. package/dist/electron/modules/license.d.ts +25 -0
  126. package/dist/electron/modules/license.d.ts.map +1 -0
  127. package/dist/electron/modules/license.js +175 -0
  128. package/dist/electron/modules/license.js.map +1 -0
  129. package/dist/electron/modules/mcp-config.d.ts +16 -0
  130. package/dist/electron/modules/mcp-config.d.ts.map +1 -0
  131. package/dist/electron/modules/mcp-config.js +146 -0
  132. package/dist/electron/modules/mcp-config.js.map +1 -0
  133. package/dist/electron/modules/ocr.d.ts +3 -0
  134. package/dist/electron/modules/ocr.d.ts.map +1 -0
  135. package/dist/electron/modules/ocr.js +176 -0
  136. package/dist/electron/modules/ocr.js.map +1 -0
  137. package/dist/electron/modules/pin-window.d.ts +3 -0
  138. package/dist/electron/modules/pin-window.d.ts.map +1 -0
  139. package/dist/electron/modules/pin-window.js +63 -0
  140. package/dist/electron/modules/pin-window.js.map +1 -0
  141. package/dist/electron/modules/recording/ai-analysis.d.ts +8 -0
  142. package/dist/electron/modules/recording/ai-analysis.d.ts.map +1 -0
  143. package/dist/electron/modules/recording/ai-analysis.js +88 -0
  144. package/dist/electron/modules/recording/ai-analysis.js.map +1 -0
  145. package/dist/electron/modules/recording/capture-queue.d.ts +48 -0
  146. package/dist/electron/modules/recording/capture-queue.d.ts.map +1 -0
  147. package/dist/electron/modules/recording/capture-queue.js +376 -0
  148. package/dist/electron/modules/recording/capture-queue.js.map +1 -0
  149. package/dist/electron/modules/recording/cli.d.ts +13 -0
  150. package/dist/electron/modules/recording/cli.d.ts.map +1 -0
  151. package/dist/electron/modules/recording/cli.js +135 -0
  152. package/dist/electron/modules/recording/cli.js.map +1 -0
  153. package/dist/electron/modules/recording/http-api.d.ts +3 -0
  154. package/dist/electron/modules/recording/http-api.d.ts.map +1 -0
  155. package/dist/electron/modules/recording/http-api.js +236 -0
  156. package/dist/electron/modules/recording/http-api.js.map +1 -0
  157. package/dist/electron/modules/recording/index.d.ts +15 -0
  158. package/dist/electron/modules/recording/index.d.ts.map +1 -0
  159. package/dist/electron/modules/recording/index.js +148 -0
  160. package/dist/electron/modules/recording/index.js.map +1 -0
  161. package/dist/electron/modules/recording/input-hook-provider.d.ts +15 -0
  162. package/dist/electron/modules/recording/input-hook-provider.d.ts.map +1 -0
  163. package/dist/electron/modules/recording/input-hook-provider.js +5 -0
  164. package/dist/electron/modules/recording/input-hook-provider.js.map +1 -0
  165. package/dist/electron/modules/recording/mcp-tool.d.ts +13 -0
  166. package/dist/electron/modules/recording/mcp-tool.d.ts.map +1 -0
  167. package/dist/electron/modules/recording/mcp-tool.js +81 -0
  168. package/dist/electron/modules/recording/mcp-tool.js.map +1 -0
  169. package/dist/electron/modules/recording/providers/periodic-provider.d.ts +15 -0
  170. package/dist/electron/modules/recording/providers/periodic-provider.d.ts.map +1 -0
  171. package/dist/electron/modules/recording/providers/periodic-provider.js +55 -0
  172. package/dist/electron/modules/recording/providers/periodic-provider.js.map +1 -0
  173. package/dist/electron/modules/recording/providers/provider-factory.d.ts +9 -0
  174. package/dist/electron/modules/recording/providers/provider-factory.d.ts.map +1 -0
  175. package/dist/electron/modules/recording/providers/provider-factory.js +70 -0
  176. package/dist/electron/modules/recording/providers/provider-factory.js.map +1 -0
  177. package/dist/electron/modules/recording/providers/uiohook-provider.d.ts +19 -0
  178. package/dist/electron/modules/recording/providers/uiohook-provider.d.ts.map +1 -0
  179. package/dist/electron/modules/recording/providers/uiohook-provider.js +263 -0
  180. package/dist/electron/modules/recording/providers/uiohook-provider.js.map +1 -0
  181. package/dist/electron/modules/recording/recording-session.d.ts +25 -0
  182. package/dist/electron/modules/recording/recording-session.d.ts.map +1 -0
  183. package/dist/electron/modules/recording/recording-session.js +317 -0
  184. package/dist/electron/modules/recording/recording-session.js.map +1 -0
  185. package/dist/electron/modules/recording/session-alignment.d.ts +32 -0
  186. package/dist/electron/modules/recording/session-alignment.d.ts.map +1 -0
  187. package/dist/electron/modules/recording/session-alignment.js +103 -0
  188. package/dist/electron/modules/recording/session-alignment.js.map +1 -0
  189. package/dist/electron/modules/recording/session-export.d.ts +2 -0
  190. package/dist/electron/modules/recording/session-export.d.ts.map +1 -0
  191. package/dist/electron/modules/recording/session-export.js +287 -0
  192. package/dist/electron/modules/recording/session-export.js.map +1 -0
  193. package/dist/electron/modules/recording/trigger-engine.d.ts +62 -0
  194. package/dist/electron/modules/recording/trigger-engine.d.ts.map +1 -0
  195. package/dist/electron/modules/recording/trigger-engine.js +546 -0
  196. package/dist/electron/modules/recording/trigger-engine.js.map +1 -0
  197. package/dist/electron/modules/recording/visual-diff.d.ts +17 -0
  198. package/dist/electron/modules/recording/visual-diff.d.ts.map +1 -0
  199. package/dist/electron/modules/recording/visual-diff.js +109 -0
  200. package/dist/electron/modules/recording/visual-diff.js.map +1 -0
  201. package/dist/electron/modules/redact.d.ts +34 -0
  202. package/dist/electron/modules/redact.d.ts.map +1 -0
  203. package/dist/electron/modules/redact.js +583 -0
  204. package/dist/electron/modules/redact.js.map +1 -0
  205. package/dist/electron/modules/scroll-capture.d.ts +19 -0
  206. package/dist/electron/modules/scroll-capture.d.ts.map +1 -0
  207. package/dist/electron/modules/scroll-capture.js +185 -0
  208. package/dist/electron/modules/scroll-capture.js.map +1 -0
  209. package/dist/electron/modules/store.d.ts +59 -0
  210. package/dist/electron/modules/store.d.ts.map +1 -0
  211. package/dist/electron/modules/store.js +100 -0
  212. package/dist/electron/modules/store.js.map +1 -0
  213. package/dist/electron/modules/tce/content-analyzer.d.ts +20 -0
  214. package/dist/electron/modules/tce/content-analyzer.d.ts.map +1 -0
  215. package/dist/electron/modules/tce/content-analyzer.js +123 -0
  216. package/dist/electron/modules/tce/content-analyzer.js.map +1 -0
  217. package/dist/electron/modules/tce/index.d.ts +54 -0
  218. package/dist/electron/modules/tce/index.d.ts.map +1 -0
  219. package/dist/electron/modules/tce/index.js +174 -0
  220. package/dist/electron/modules/tce/index.js.map +1 -0
  221. package/dist/electron/modules/tce/layout-engine.d.ts +68 -0
  222. package/dist/electron/modules/tce/layout-engine.d.ts.map +1 -0
  223. package/dist/electron/modules/tce/layout-engine.js +313 -0
  224. package/dist/electron/modules/tce/layout-engine.js.map +1 -0
  225. package/dist/electron/modules/tce/renderer.d.ts +16 -0
  226. package/dist/electron/modules/tce/renderer.d.ts.map +1 -0
  227. package/dist/electron/modules/tce/renderer.js +196 -0
  228. package/dist/electron/modules/tce/renderer.js.map +1 -0
  229. package/dist/electron/modules/tce/themes.d.ts +14 -0
  230. package/dist/electron/modules/tce/themes.d.ts.map +1 -0
  231. package/dist/electron/modules/tce/themes.js +68 -0
  232. package/dist/electron/modules/tce/themes.js.map +1 -0
  233. package/dist/electron/modules/tce/token-estimator.d.ts +30 -0
  234. package/dist/electron/modules/tce/token-estimator.d.ts.map +1 -0
  235. package/dist/electron/modules/tce/token-estimator.js +59 -0
  236. package/dist/electron/modules/tce/token-estimator.js.map +1 -0
  237. package/dist/electron/modules/telemetry.d.ts +44 -0
  238. package/dist/electron/modules/telemetry.d.ts.map +1 -0
  239. package/dist/electron/modules/telemetry.js +316 -0
  240. package/dist/electron/modules/telemetry.js.map +1 -0
  241. package/dist/electron/modules/tray.d.ts +22 -0
  242. package/dist/electron/modules/tray.d.ts.map +1 -0
  243. package/dist/electron/modules/tray.js +221 -0
  244. package/dist/electron/modules/tray.js.map +1 -0
  245. package/dist/electron/modules/updater.d.ts +14 -0
  246. package/dist/electron/modules/updater.d.ts.map +1 -0
  247. package/dist/electron/modules/updater.js +102 -0
  248. package/dist/electron/modules/updater.js.map +1 -0
  249. package/dist/electron/modules/usage-link.d.ts +7 -0
  250. package/dist/electron/modules/usage-link.d.ts.map +1 -0
  251. package/dist/electron/modules/usage-link.js +63 -0
  252. package/dist/electron/modules/usage-link.js.map +1 -0
  253. package/dist/electron/modules/version-check.d.ts +3 -0
  254. package/dist/electron/modules/version-check.d.ts.map +1 -0
  255. package/dist/electron/modules/version-check.js +76 -0
  256. package/dist/electron/modules/version-check.js.map +1 -0
  257. package/dist/electron/modules/window-picker.d.ts +6 -0
  258. package/dist/electron/modules/window-picker.d.ts.map +1 -0
  259. package/dist/electron/modules/window-picker.js +192 -0
  260. package/dist/electron/modules/window-picker.js.map +1 -0
  261. package/dist/headless/electron/ai/ai-client.js +204 -0
  262. package/dist/headless/electron/ai/context-builder.js +27 -0
  263. package/dist/headless/electron/ai/instruction-parser.js +46 -0
  264. package/dist/headless/electron/core/auth-store.js +85 -0
  265. package/dist/headless/electron/core/config.js +80 -0
  266. package/dist/headless/electron/core/file-logger.js +73 -0
  267. package/dist/headless/electron/core/json-store.js +117 -0
  268. package/dist/headless/electron/core/paths.js +116 -0
  269. package/dist/headless/electron/core/platform.js +17 -0
  270. package/dist/headless/electron/core/process-coord.js +123 -0
  271. package/dist/headless/electron/db/database.js +636 -0
  272. package/dist/headless/electron/db/models.js +3 -0
  273. package/dist/headless/electron/logger.js +17 -0
  274. package/dist/headless/electron/modules/active-window.js +67 -0
  275. package/dist/headless/electron/modules/api-server.js +1323 -0
  276. package/dist/headless/electron/modules/auth.js +149 -0
  277. package/dist/headless/electron/modules/azure-speech-realtime.js +353 -0
  278. package/dist/headless/electron/modules/capture.js +138 -0
  279. package/dist/headless/electron/modules/clipboard.js +25 -0
  280. package/dist/headless/electron/modules/dictation.js +1057 -0
  281. package/dist/headless/electron/modules/keystroke.js +52 -0
  282. package/dist/headless/electron/modules/license.js +174 -0
  283. package/dist/headless/electron/modules/mcp-config.js +145 -0
  284. package/dist/headless/electron/modules/ocr.js +175 -0
  285. package/dist/headless/electron/modules/recording/ai-analysis.js +87 -0
  286. package/dist/headless/electron/modules/recording/capture-queue.js +375 -0
  287. package/dist/headless/electron/modules/recording/cli.js +134 -0
  288. package/dist/headless/electron/modules/recording/http-api.js +235 -0
  289. package/dist/headless/electron/modules/recording/index.js +147 -0
  290. package/dist/headless/electron/modules/recording/input-hook-provider.js +4 -0
  291. package/dist/headless/electron/modules/recording/mcp-tool.js +80 -0
  292. package/dist/headless/electron/modules/recording/providers/periodic-provider.js +54 -0
  293. package/dist/headless/electron/modules/recording/providers/provider-factory.js +69 -0
  294. package/dist/headless/electron/modules/recording/providers/uiohook-provider.js +262 -0
  295. package/dist/headless/electron/modules/recording/recording-session.js +316 -0
  296. package/dist/headless/electron/modules/recording/session-alignment.js +102 -0
  297. package/dist/headless/electron/modules/recording/session-export.js +286 -0
  298. package/dist/headless/electron/modules/recording/trigger-engine.js +545 -0
  299. package/dist/headless/electron/modules/recording/visual-diff.js +108 -0
  300. package/dist/headless/electron/modules/redact.js +582 -0
  301. package/dist/headless/electron/modules/store.js +99 -0
  302. package/dist/headless/electron/modules/tce/content-analyzer.js +122 -0
  303. package/dist/headless/electron/modules/tce/index.js +173 -0
  304. package/dist/headless/electron/modules/tce/layout-engine.js +312 -0
  305. package/dist/headless/electron/modules/tce/renderer.js +195 -0
  306. package/dist/headless/electron/modules/tce/themes.js +67 -0
  307. package/dist/headless/electron/modules/tce/token-estimator.js +58 -0
  308. package/dist/headless/electron/modules/telemetry.js +315 -0
  309. package/dist/headless/headless/capture-hotkey.js +155 -0
  310. package/dist/headless/headless/cli-auth.js +158 -0
  311. package/dist/headless/headless/cli.js +220 -0
  312. package/dist/headless/headless/dictation-hotkey.js +360 -0
  313. package/dist/headless/headless/mic-capture.js +312 -0
  314. package/dist/headless/headless/platform-headless.js +121 -0
  315. package/dist/headless/headless/server.js +159 -0
  316. package/dist/headless/mic-capture.d.ts +29 -0
  317. package/dist/headless/mic-capture.d.ts.map +1 -0
  318. package/dist/headless/mic-capture.js +313 -0
  319. package/dist/headless/mic-capture.js.map +1 -0
  320. package/dist/headless/shared/constants.js +63 -0
  321. package/dist/headless/shared/design-tokens.js +189 -0
  322. package/dist/headless/shared/recording-types.js +93 -0
  323. package/dist/headless/shared/types.js +3 -0
  324. package/dist/shared/constants.d.ts +98 -0
  325. package/dist/shared/constants.d.ts.map +1 -0
  326. package/dist/shared/constants.js +64 -0
  327. package/dist/shared/constants.js.map +1 -0
  328. package/dist/shared/design-tokens.d.ts +112 -0
  329. package/dist/shared/design-tokens.d.ts.map +1 -0
  330. package/dist/shared/design-tokens.js +190 -0
  331. package/dist/shared/design-tokens.js.map +1 -0
  332. package/dist/shared/recording-types.d.ts +174 -0
  333. package/dist/shared/recording-types.d.ts.map +1 -0
  334. package/dist/shared/recording-types.js +94 -0
  335. package/dist/shared/recording-types.js.map +1 -0
  336. package/dist/shared/types.d.ts +135 -0
  337. package/dist/shared/types.d.ts.map +1 -0
  338. package/dist/shared/types.js +4 -0
  339. package/dist/shared/types.js.map +1 -0
  340. package/mcp-server/dist/api-client.js +261 -0
  341. package/mcp-server/dist/index.js +824 -0
  342. package/mcp-server/package.json +16 -0
  343. package/package.json +125 -0
@@ -0,0 +1,545 @@
1
+ "use strict";
2
+ // Trigger Engine — finite state machine that converts raw input events to capture requests.
3
+ // Implements all 11 trigger types from the spec.
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.TriggerEngine = void 0;
9
+ const electron_1 = require("electron");
10
+ const logger_1 = __importDefault(require("../../logger"));
11
+ // Thresholds
12
+ const CLICK_POSITION_TOLERANCE = 5;
13
+ const CLICK_DURATION_MAX = 300;
14
+ const DOUBLE_CLICK_WINDOW = 250;
15
+ const DOUBLE_CLICK_POSITION_TOLERANCE = 10;
16
+ const CLICK_CAPTURE_DELAY = 50;
17
+ const RIGHT_CLICK_DELAY = 300;
18
+ const DRAG_THRESHOLD = 20;
19
+ const DRAG_END_DELAY = 200;
20
+ const TYPING_SILENCE_MS = 1500;
21
+ const TYPING_CAPTURE_DELAY = 200;
22
+ const ENTER_DELAY = 200;
23
+ const COMBO_DELAY = 300;
24
+ const SCROLL_SILENCE_MS = 800;
25
+ const SCROLL_CAPTURE_DELAY = 100;
26
+ const FOCUS_CHANGE_DELAY = 200;
27
+ const BURST_WINDOW_MS = 1000;
28
+ const BURST_COOLDOWN_MS = 500;
29
+ // Modifier keycodes (uiohook)
30
+ const MODIFIER_KEYS = new Set(['Control', 'Shift', 'Alt', 'Meta', 'CapsLock']);
31
+ // Printable character detection
32
+ function isPrintableKey(keyName) {
33
+ if (MODIFIER_KEYS.has(keyName))
34
+ return false;
35
+ if ([
36
+ 'Escape',
37
+ 'Tab',
38
+ 'Backspace',
39
+ 'Delete',
40
+ 'Insert',
41
+ 'ArrowUp',
42
+ 'ArrowDown',
43
+ 'ArrowLeft',
44
+ 'ArrowRight',
45
+ 'Home',
46
+ 'End',
47
+ 'PageUp',
48
+ 'PageDown',
49
+ 'F1',
50
+ 'F2',
51
+ 'F3',
52
+ 'F4',
53
+ 'F5',
54
+ 'F6',
55
+ 'F7',
56
+ 'F8',
57
+ 'F9',
58
+ 'F10',
59
+ 'F11',
60
+ 'F12',
61
+ 'NumLock',
62
+ 'ScrollLock',
63
+ 'Enter',
64
+ ].includes(keyName))
65
+ return false;
66
+ return true;
67
+ }
68
+ // Password field heuristic
69
+ const PASSWORD_PATTERNS = /password|login|sign.?in|authenticate|credential|passcode/i;
70
+ function shouldMaskText(windowTitle) {
71
+ if (!windowTitle)
72
+ return false;
73
+ return PASSWORD_PATTERNS.test(windowTitle);
74
+ }
75
+ // Exclude list — only exclude SuperBased's own process name, NOT 'electron' generically
76
+ // (since Electron apps show as 'electron.exe' on Windows, matching 'electron' would
77
+ // exclude events any time a SuperBased window has focus)
78
+ const DEFAULT_EXCLUDE_PROCESSES = ['superbased.exe'];
79
+ class TriggerEngine {
80
+ state = { name: 'idle' };
81
+ config;
82
+ timers = new Map();
83
+ onCapture;
84
+ lastActiveWindow = null;
85
+ maskTypedText;
86
+ excludeProcesses;
87
+ scope;
88
+ targetProcessName;
89
+ maxCapturesPerSecond;
90
+ minCaptureInterval;
91
+ lastCaptureTime = 0;
92
+ // Burst protection
93
+ recentCaptureTimes = [];
94
+ burstMode = false;
95
+ periodicTimer = null;
96
+ constructor(options) {
97
+ this.config = options.config;
98
+ this.onCapture = options.onCapture;
99
+ this.maskTypedText = options.maskTypedText;
100
+ this.excludeProcesses = options.excludeProcesses || DEFAULT_EXCLUDE_PROCESSES;
101
+ this.scope = options.scope || 'all';
102
+ this.targetProcessName = options.targetProcessName;
103
+ this.maxCapturesPerSecond = options.maxCapturesPerSecond || 3;
104
+ this.minCaptureInterval = options.minCaptureInterval || 0;
105
+ }
106
+ startPeriodicTimer() {
107
+ if (!this.config.periodic || !this.config.periodicInterval)
108
+ return;
109
+ this.periodicTimer = setInterval(() => {
110
+ this.emitCapture({ type: 'periodic', timestamp: Date.now() }, 0);
111
+ }, this.config.periodicInterval);
112
+ }
113
+ stopPeriodicTimer() {
114
+ if (this.periodicTimer) {
115
+ clearInterval(this.periodicTimer);
116
+ this.periodicTimer = null;
117
+ }
118
+ }
119
+ // Throttle mousemove logging (fires hundreds of times per second)
120
+ lastMoveLog = 0;
121
+ eventCount = 0;
122
+ droppedScopeCount = 0;
123
+ droppedExcludeCount = 0;
124
+ processEvent(event) {
125
+ this.eventCount++;
126
+ // Log non-mousemove events always; mousemove only every 2 seconds
127
+ const isMove = event.type === 'mousemove';
128
+ if (!isMove) {
129
+ logger_1.default.info(`[TriggerEngine] Event #${this.eventCount}: ${event.type}, state=${this.state.name}, activeWin=${this.lastActiveWindow?.process || 'unknown'}`);
130
+ }
131
+ else if (Date.now() - this.lastMoveLog > 2000) {
132
+ logger_1.default.info(`[TriggerEngine] mousemove heartbeat (event #${this.eventCount}, state=${this.state.name}, droppedScope=${this.droppedScopeCount}, droppedExclude=${this.droppedExcludeCount})`);
133
+ this.lastMoveLog = Date.now();
134
+ this.droppedScopeCount = 0;
135
+ this.droppedExcludeCount = 0;
136
+ }
137
+ // Application scope filtering
138
+ if (!this.isInScope()) {
139
+ if (!isMove)
140
+ logger_1.default.info(`[TriggerEngine] DROPPED by scope filter`);
141
+ else
142
+ this.droppedScopeCount++;
143
+ return;
144
+ }
145
+ // Exclude processes check
146
+ if (this.isExcludedProcess()) {
147
+ if (!isMove)
148
+ logger_1.default.info(`[TriggerEngine] DROPPED by exclude filter (process: ${this.lastActiveWindow?.process})`);
149
+ else
150
+ this.droppedExcludeCount++;
151
+ return;
152
+ }
153
+ // Check for focus/window change on every event (orthogonal trigger)
154
+ this.checkFocusChange(event.timestamp);
155
+ // Route to state-specific handler
156
+ switch (this.state.name) {
157
+ case 'idle':
158
+ this.handleIdle(event);
159
+ break;
160
+ case 'mouse_down':
161
+ this.handleMouseDown(event);
162
+ break;
163
+ case 'click_pending':
164
+ this.handleClickPending(event);
165
+ break;
166
+ case 'dragging':
167
+ this.handleDragging(event);
168
+ break;
169
+ case 'typing':
170
+ this.handleTyping(event);
171
+ break;
172
+ case 'scrolling':
173
+ this.handleScrolling(event);
174
+ break;
175
+ case 'combo_pending':
176
+ this.handleComboPending(event);
177
+ break;
178
+ }
179
+ }
180
+ // ── IDLE State ──
181
+ handleIdle(event) {
182
+ if (event.type === 'mousedown') {
183
+ const e = event;
184
+ logger_1.default.info(`[TriggerEngine] IDLE->MOUSE_DOWN at (${e.x},${e.y}) button=${e.button}`);
185
+ this.state = { name: 'mouse_down', x: e.x, y: e.y, button: e.button, time: event.timestamp };
186
+ return;
187
+ }
188
+ if (event.type === 'keydown') {
189
+ const e = event;
190
+ const hasModifier = e.modifiers.ctrl || e.modifiers.alt || e.modifiers.meta;
191
+ // Key combo: modifier + non-modifier
192
+ if (hasModifier && !MODIFIER_KEYS.has(e.keyName) && this.config.keyCombos) {
193
+ const keys = [];
194
+ if (e.modifiers.ctrl)
195
+ keys.push('Ctrl');
196
+ if (e.modifiers.alt)
197
+ keys.push('Alt');
198
+ if (e.modifiers.meta)
199
+ keys.push('Meta');
200
+ if (e.modifiers.shift)
201
+ keys.push('Shift');
202
+ keys.push(e.keyName);
203
+ this.state = { name: 'combo_pending', keys, time: event.timestamp };
204
+ this.setTimer('combo_timeout', COMBO_DELAY, () => {
205
+ if (this.state.name === 'combo_pending') {
206
+ const cs = this.state;
207
+ this.emitCapture({ type: 'key_combo', timestamp: cs.time, keys: cs.keys }, COMBO_DELAY);
208
+ this.state = { name: 'idle' };
209
+ }
210
+ });
211
+ return;
212
+ }
213
+ // Enter key (not during typing — that's handled in TYPING state)
214
+ if (e.keyName === 'Enter' && this.config.enterKey) {
215
+ this.emitCapture({ type: 'key_enter', timestamp: event.timestamp }, ENTER_DELAY);
216
+ return;
217
+ }
218
+ // Printable character → start typing
219
+ if (isPrintableKey(e.keyName) && !hasModifier && this.config.typingComplete) {
220
+ const text = this.maskTypedText || shouldMaskText(this.lastActiveWindow?.title ?? null) ? '' : e.keyName;
221
+ this.state = { name: 'typing', buffer: text, lastKeyTime: event.timestamp, startTime: event.timestamp };
222
+ this.setTimer('typing_silence', TYPING_SILENCE_MS, () => this.flushTyping());
223
+ return;
224
+ }
225
+ }
226
+ if (event.type === 'wheel' && this.config.scrollStop) {
227
+ const e = event;
228
+ this.state = {
229
+ name: 'scrolling',
230
+ totalDelta: Math.abs(e.deltaY) + Math.abs(e.deltaX),
231
+ lastWheelTime: event.timestamp,
232
+ };
233
+ this.setTimer('scroll_silence', SCROLL_SILENCE_MS, () => this.flushScroll());
234
+ return;
235
+ }
236
+ }
237
+ // ── MOUSE_DOWN State ──
238
+ handleMouseDown(event) {
239
+ const md = this.state;
240
+ if (event.type === 'mouseup') {
241
+ const e = event;
242
+ const elapsed = event.timestamp - md.time;
243
+ const dx = Math.abs(e.x - md.x);
244
+ const dy = Math.abs(e.y - md.y);
245
+ const withinPos = dx <= CLICK_POSITION_TOLERANCE && dy <= CLICK_POSITION_TOLERANCE;
246
+ if (withinPos) {
247
+ // Right-click
248
+ if (e.button === 2) {
249
+ if (this.config.rightClick) {
250
+ this.emitCapture({ type: 'right_click', timestamp: event.timestamp, x: e.x, y: e.y, button: 2 }, RIGHT_CLICK_DELAY);
251
+ }
252
+ this.state = { name: 'idle' };
253
+ return;
254
+ }
255
+ // Left/middle click
256
+ if (e.button === 1 && elapsed <= CLICK_DURATION_MAX) {
257
+ // Start double-click detection
258
+ this.state = { name: 'click_pending', x: e.x, y: e.y, button: e.button, time: event.timestamp };
259
+ this.setTimer('double_click_detect', DOUBLE_CLICK_WINDOW, () => {
260
+ if (this.state.name === 'click_pending') {
261
+ if (this.config.click) {
262
+ const cp = this.state;
263
+ this.emitCapture({ type: 'click', timestamp: cp.time, x: cp.x, y: cp.y, button: 1 }, CLICK_CAPTURE_DELAY);
264
+ }
265
+ this.state = { name: 'idle' };
266
+ }
267
+ });
268
+ }
269
+ else {
270
+ // Long press — still a click
271
+ if (this.config.click) {
272
+ this.emitCapture({ type: 'click', timestamp: event.timestamp, x: e.x, y: e.y, button: e.button }, CLICK_CAPTURE_DELAY);
273
+ }
274
+ this.state = { name: 'idle' };
275
+ }
276
+ }
277
+ else {
278
+ // Movement detected but mouseup → drag ended quickly
279
+ if (this.config.dragEnd) {
280
+ this.emitCapture({ type: 'drag_end', timestamp: event.timestamp, x: e.x, y: e.y }, DRAG_END_DELAY);
281
+ }
282
+ this.state = { name: 'idle' };
283
+ }
284
+ return;
285
+ }
286
+ if (event.type === 'mousemove') {
287
+ const e = event;
288
+ const dx = Math.abs(e.x - md.x);
289
+ const dy = Math.abs(e.y - md.y);
290
+ if (dx > DRAG_THRESHOLD || dy > DRAG_THRESHOLD) {
291
+ this.state = { name: 'dragging', startX: md.x, startY: md.y };
292
+ }
293
+ }
294
+ }
295
+ // ── CLICK_PENDING State (double-click detection) ──
296
+ handleClickPending(event) {
297
+ const cp = this.state;
298
+ if (event.type === 'mouseup') {
299
+ const e = event;
300
+ const elapsed = event.timestamp - cp.time;
301
+ const dx = Math.abs(e.x - cp.x);
302
+ const dy = Math.abs(e.y - cp.y);
303
+ if (elapsed <= DOUBLE_CLICK_WINDOW &&
304
+ dx <= DOUBLE_CLICK_POSITION_TOLERANCE &&
305
+ dy <= DOUBLE_CLICK_POSITION_TOLERANCE) {
306
+ this.clearTimer('double_click_detect');
307
+ if (this.config.doubleClick) {
308
+ this.emitCapture({ type: 'double_click', timestamp: event.timestamp, x: e.x, y: e.y, button: 1 }, CLICK_CAPTURE_DELAY);
309
+ }
310
+ this.state = { name: 'idle' };
311
+ }
312
+ }
313
+ }
314
+ // ── DRAGGING State ──
315
+ handleDragging(event) {
316
+ if (event.type === 'mouseup') {
317
+ const e = event;
318
+ if (this.config.dragEnd) {
319
+ this.emitCapture({ type: 'drag_end', timestamp: event.timestamp, x: e.x, y: e.y }, DRAG_END_DELAY);
320
+ }
321
+ this.state = { name: 'idle' };
322
+ }
323
+ // mousemove during drag: ignore (we don't track drag path)
324
+ }
325
+ // ── TYPING State ──
326
+ handleTyping(event) {
327
+ const ts = this.state;
328
+ if (event.type === 'mousedown') {
329
+ // Flush typing buffer immediately, then process mousedown
330
+ this.flushTyping();
331
+ this.handleIdle(event);
332
+ return;
333
+ }
334
+ if (event.type === 'keydown') {
335
+ const e = event;
336
+ // Enter during typing: flush buffer first, then emit key_enter
337
+ if (e.keyName === 'Enter') {
338
+ this.flushTyping();
339
+ if (this.config.enterKey) {
340
+ this.emitCapture({ type: 'key_enter', timestamp: event.timestamp }, ENTER_DELAY);
341
+ }
342
+ return;
343
+ }
344
+ // Modifier combo during typing: flush buffer first
345
+ if ((e.modifiers.ctrl || e.modifiers.alt || e.modifiers.meta) && !MODIFIER_KEYS.has(e.keyName)) {
346
+ this.flushTyping();
347
+ this.handleIdle(event);
348
+ return;
349
+ }
350
+ // More printable keys → accumulate
351
+ if (isPrintableKey(e.keyName)) {
352
+ const shouldMask = this.maskTypedText || shouldMaskText(this.lastActiveWindow?.title ?? null);
353
+ this.state = {
354
+ ...ts,
355
+ buffer: shouldMask ? ts.buffer : ts.buffer + e.keyName,
356
+ lastKeyTime: event.timestamp,
357
+ };
358
+ this.setTimer('typing_silence', TYPING_SILENCE_MS, () => this.flushTyping());
359
+ }
360
+ return;
361
+ }
362
+ if (event.type === 'wheel') {
363
+ // Scroll during typing: flush typing first
364
+ this.flushTyping();
365
+ this.handleIdle(event);
366
+ }
367
+ }
368
+ flushTyping() {
369
+ this.clearTimer('typing_silence');
370
+ if (this.state.name !== 'typing')
371
+ return;
372
+ const ts = this.state;
373
+ if (this.config.typingComplete) {
374
+ const shouldMask = this.maskTypedText || shouldMaskText(this.lastActiveWindow?.title ?? null);
375
+ this.emitCapture({
376
+ type: 'typing_complete',
377
+ timestamp: ts.lastKeyTime,
378
+ typedLength: ts.buffer.length,
379
+ typedText: shouldMask ? undefined : ts.buffer,
380
+ }, TYPING_CAPTURE_DELAY);
381
+ }
382
+ this.state = { name: 'idle' };
383
+ }
384
+ // ── SCROLLING State ──
385
+ handleScrolling(event) {
386
+ const ss = this.state;
387
+ if (event.type === 'wheel') {
388
+ const e = event;
389
+ this.state = {
390
+ ...ss,
391
+ totalDelta: ss.totalDelta + Math.abs(e.deltaY) + Math.abs(e.deltaX),
392
+ lastWheelTime: event.timestamp,
393
+ };
394
+ this.setTimer('scroll_silence', SCROLL_SILENCE_MS, () => this.flushScroll());
395
+ return;
396
+ }
397
+ if (event.type === 'mousedown') {
398
+ // Click after scrolling: flush scroll, process click
399
+ this.flushScroll();
400
+ this.handleIdle(event);
401
+ return;
402
+ }
403
+ if (event.type === 'keydown') {
404
+ this.flushScroll();
405
+ this.handleIdle(event);
406
+ }
407
+ }
408
+ flushScroll() {
409
+ this.clearTimer('scroll_silence');
410
+ if (this.state.name !== 'scrolling')
411
+ return;
412
+ const ss = this.state;
413
+ if (this.config.scrollStop) {
414
+ this.emitCapture({
415
+ type: 'scroll_stop',
416
+ timestamp: ss.lastWheelTime,
417
+ scrollDelta: ss.totalDelta,
418
+ }, SCROLL_CAPTURE_DELAY);
419
+ }
420
+ this.state = { name: 'idle' };
421
+ }
422
+ // ── COMBO_PENDING State ──
423
+ handleComboPending(event) {
424
+ // Combo already scheduled via timer. If new event arrives, ignore unless it's another keydown.
425
+ if (event.type === 'mousedown' || event.type === 'wheel') {
426
+ // Flush combo, process new event
427
+ this.clearTimer('combo_timeout');
428
+ const cs = this.state;
429
+ this.emitCapture({ type: 'key_combo', timestamp: cs.time, keys: cs.keys }, 0);
430
+ this.state = { name: 'idle' };
431
+ this.handleIdle(event);
432
+ }
433
+ }
434
+ // ── Focus Change Detection (orthogonal) ──
435
+ checkFocusChange(_timestamp) {
436
+ // This will be called from recording-session which polls active window
437
+ // The actual comparison is done via setActiveWindow
438
+ }
439
+ setActiveWindow(info) {
440
+ if (!this.lastActiveWindow) {
441
+ this.lastActiveWindow = info;
442
+ return;
443
+ }
444
+ if (this.lastActiveWindow.title !== info.title || this.lastActiveWindow.process !== info.process) {
445
+ const previousWindow = this.lastActiveWindow.title;
446
+ this.lastActiveWindow = info;
447
+ if (this.config.focusChange) {
448
+ this.emitCapture({
449
+ type: 'focus_change',
450
+ timestamp: Date.now(),
451
+ windowTitle: info.title,
452
+ processName: info.process,
453
+ previousWindow,
454
+ }, FOCUS_CHANGE_DELAY);
455
+ }
456
+ }
457
+ }
458
+ // ── Manual Capture ──
459
+ emitManualCapture() {
460
+ this.emitCapture({ type: 'manual', timestamp: Date.now() }, 0);
461
+ }
462
+ // ── Scope & Exclusion Filtering ──
463
+ isInScope() {
464
+ if (this.scope === 'all')
465
+ return true;
466
+ if (!this.lastActiveWindow)
467
+ return true; // Allow until we know the window
468
+ if (this.scope === 'specific_app' && this.targetProcessName) {
469
+ return this.lastActiveWindow.process.toLowerCase().includes(this.targetProcessName.toLowerCase());
470
+ }
471
+ return true;
472
+ }
473
+ isExcludedProcess() {
474
+ if (!this.lastActiveWindow)
475
+ return false;
476
+ const proc = this.lastActiveWindow.process.toLowerCase();
477
+ return this.excludeProcesses.some((p) => proc.includes(p.toLowerCase()));
478
+ }
479
+ // ── Burst Protection ──
480
+ emitCapture(trigger, delay) {
481
+ // Convert click coordinates to physical pixels matching screenshot resolution.
482
+ // On macOS, uiohook-napi reports CGEvent coordinates in logical points.
483
+ // On Windows, uiohook uses MSLLHOOKSTRUCT which returns physical pixels
484
+ // when the process is DPI-aware (Electron's default).
485
+ if (trigger.x !== undefined && trigger.y !== undefined && process.platform === 'darwin') {
486
+ const scaleFactor = electron_1.screen.getPrimaryDisplay().scaleFactor || 1;
487
+ trigger.x = Math.round(trigger.x * scaleFactor);
488
+ trigger.y = Math.round(trigger.y * scaleFactor);
489
+ }
490
+ logger_1.default.info(`[TriggerEngine] Emitting capture: ${trigger.type}, delay=${delay}ms`);
491
+ const now = Date.now();
492
+ // Rate limit: never emit captures faster than minCaptureInterval
493
+ if (this.minCaptureInterval > 0 && now - this.lastCaptureTime < this.minCaptureInterval) {
494
+ logger_1.default.info(`[TriggerEngine] Rate limited (${now - this.lastCaptureTime}ms < ${this.minCaptureInterval}ms)`);
495
+ return;
496
+ }
497
+ // Clean old entries from burst window
498
+ this.recentCaptureTimes = this.recentCaptureTimes.filter((t) => now - t < BURST_WINDOW_MS);
499
+ // Check burst
500
+ if (this.recentCaptureTimes.length >= this.maxCapturesPerSecond) {
501
+ if (!this.burstMode) {
502
+ this.burstMode = true;
503
+ // Schedule a single capture after burst cooldown
504
+ this.setTimer('burst_cooldown', BURST_COOLDOWN_MS, () => {
505
+ this.burstMode = false;
506
+ this.onCapture({ trigger, delay: 0, priority: 'normal' });
507
+ this.recentCaptureTimes = [Date.now()];
508
+ });
509
+ }
510
+ return;
511
+ }
512
+ this.lastCaptureTime = now;
513
+ this.recentCaptureTimes.push(now);
514
+ this.onCapture({ trigger, delay, priority: 'normal' });
515
+ }
516
+ // ── Utilities ──
517
+ setTimer(name, ms, callback) {
518
+ this.clearTimer(name);
519
+ this.timers.set(name, setTimeout(callback, ms));
520
+ }
521
+ clearTimer(name) {
522
+ const t = this.timers.get(name);
523
+ if (t) {
524
+ clearTimeout(t);
525
+ this.timers.delete(name);
526
+ }
527
+ }
528
+ getState() {
529
+ return this.state;
530
+ }
531
+ updateConfig(config) {
532
+ this.config = config;
533
+ }
534
+ destroy() {
535
+ this.stopPeriodicTimer();
536
+ for (const t of this.timers.values())
537
+ clearTimeout(t);
538
+ this.timers.clear();
539
+ this.state = { name: 'idle' };
540
+ this.recentCaptureTimes = [];
541
+ this.burstMode = false;
542
+ this.lastCaptureTime = 0;
543
+ }
544
+ }
545
+ exports.TriggerEngine = TriggerEngine;
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ // Visual Diff Engine — frame-to-frame and session-to-session comparison using pixelmatch.
3
+ // Runs asynchronously (not in capture hot path).
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
17
+ }) : function(o, v) {
18
+ o["default"] = v;
19
+ });
20
+ var __importStar = (this && this.__importStar) || (function () {
21
+ var ownKeys = function(o) {
22
+ ownKeys = Object.getOwnPropertyNames || function (o) {
23
+ var ar = [];
24
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
25
+ return ar;
26
+ };
27
+ return ownKeys(o);
28
+ };
29
+ return function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ })();
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.computeFrameDiff = computeFrameDiff;
39
+ exports.classifyDiff = classifyDiff;
40
+ const path = __importStar(require("path"));
41
+ async function computeFrameDiff(currentPath, previousPath, outputDir, frameNumber) {
42
+ const sharp = require('sharp');
43
+ const pixelmatch = require('pixelmatch');
44
+ const { PNG } = require('pngjs');
45
+ // Load and normalize both images to same dimensions
46
+ const [currentMeta, previousMeta] = await Promise.all([
47
+ sharp(currentPath).metadata(),
48
+ sharp(previousPath).metadata(),
49
+ ]);
50
+ // Use the smaller dimensions to avoid mismatches
51
+ const width = Math.min(currentMeta.width || 1920, previousMeta.width || 1920);
52
+ const height = Math.min(currentMeta.height || 1080, previousMeta.height || 1080);
53
+ // For very large images, downsample to 1920x1080 for performance
54
+ const maxWidth = 1920;
55
+ const maxHeight = 1080;
56
+ const diffWidth = Math.min(width, maxWidth);
57
+ const diffHeight = Math.min(height, maxHeight);
58
+ const [currentBuf, previousBuf] = await Promise.all([
59
+ sharp(currentPath).resize(diffWidth, diffHeight, { fit: 'fill' }).raw().ensureAlpha().toBuffer(),
60
+ sharp(previousPath).resize(diffWidth, diffHeight, { fit: 'fill' }).raw().ensureAlpha().toBuffer(),
61
+ ]);
62
+ // Run pixelmatch
63
+ const diffBuffer = new Uint8Array(diffWidth * diffHeight * 4);
64
+ const numDiffPixels = pixelmatch(new Uint8Array(currentBuf), new Uint8Array(previousBuf), diffBuffer, diffWidth, diffHeight, { threshold: 0.1, includeAA: false });
65
+ const totalPixels = diffWidth * diffHeight;
66
+ const diffScore = (numDiffPixels / totalPixels) * 100;
67
+ // Find bounding box of changed region
68
+ const changedRegion = findBoundingBox(diffBuffer, diffWidth, diffHeight);
69
+ // Save diff image as WebP
70
+ const diffPng = new PNG({ width: diffWidth, height: diffHeight });
71
+ diffPng.data = Buffer.from(diffBuffer);
72
+ const pngBuf = PNG.sync.write(diffPng);
73
+ const diffImageName = `diff_${frameNumber}to${frameNumber + 1}.webp`;
74
+ const diffImagePath = path.join(outputDir, diffImageName);
75
+ await sharp(pngBuf).webp({ quality: 80 }).toFile(diffImagePath);
76
+ return { diffScore, diffImagePath, changedRegion, numDiffPixels, totalPixels };
77
+ }
78
+ function findBoundingBox(diffBuffer, width, height) {
79
+ let minX = width, minY = height, maxX = 0, maxY = 0;
80
+ let found = false;
81
+ for (let y = 0; y < height; y++) {
82
+ for (let x = 0; x < width; x++) {
83
+ const idx = (y * width + x) * 4;
84
+ // pixelmatch marks changed pixels with non-zero red channel
85
+ if (diffBuffer[idx] > 0) {
86
+ found = true;
87
+ if (x < minX)
88
+ minX = x;
89
+ if (x > maxX)
90
+ maxX = x;
91
+ if (y < minY)
92
+ minY = y;
93
+ if (y > maxY)
94
+ maxY = y;
95
+ }
96
+ }
97
+ }
98
+ if (!found)
99
+ return null;
100
+ return { x: minX, y: minY, w: maxX - minX + 1, h: maxY - minY + 1 };
101
+ }
102
+ function classifyDiff(diffScore) {
103
+ if (diffScore < 2)
104
+ return 'PASS';
105
+ if (diffScore < 10)
106
+ return 'WARN';
107
+ return 'FAIL';
108
+ }