superbased 1.6.4 → 2.0.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 (423) hide show
  1. package/README.md +169 -36
  2. package/SUPERBASED_SKILL.md +1196 -22
  3. package/dist/electron/core/input-injection/index.d.ts +6 -0
  4. package/dist/electron/core/input-injection/index.d.ts.map +1 -0
  5. package/dist/electron/core/input-injection/index.js +31 -0
  6. package/dist/electron/core/input-injection/index.js.map +1 -0
  7. package/dist/electron/core/input-injection/macos.d.ts +3 -0
  8. package/dist/electron/core/input-injection/macos.d.ts.map +1 -0
  9. package/dist/electron/core/input-injection/macos.js +14 -0
  10. package/dist/electron/core/input-injection/macos.js.map +1 -0
  11. package/dist/electron/core/input-injection/windows.d.ts +3 -0
  12. package/dist/electron/core/input-injection/windows.d.ts.map +1 -0
  13. package/dist/electron/core/input-injection/windows.js +119 -0
  14. package/dist/electron/core/input-injection/windows.js.map +1 -0
  15. package/dist/electron/core/json-store.d.ts +22 -0
  16. package/dist/electron/core/json-store.d.ts.map +1 -1
  17. package/dist/electron/core/json-store.js +61 -47
  18. package/dist/electron/core/json-store.js.map +1 -1
  19. package/dist/electron/core/platform.d.ts +1 -0
  20. package/dist/electron/core/platform.d.ts.map +1 -1
  21. package/dist/electron/core/serialize-schema.d.ts +35 -0
  22. package/dist/electron/core/serialize-schema.d.ts.map +1 -0
  23. package/dist/electron/core/serialize-schema.js +89 -0
  24. package/dist/electron/core/serialize-schema.js.map +1 -0
  25. package/dist/electron/core/settings-schema.d.ts +81 -0
  26. package/dist/electron/core/settings-schema.d.ts.map +1 -0
  27. package/dist/electron/core/settings-schema.js +1357 -0
  28. package/dist/electron/core/settings-schema.js.map +1 -0
  29. package/dist/electron/logger.d.ts.map +1 -1
  30. package/dist/electron/logger.js +22 -8
  31. package/dist/electron/logger.js.map +1 -1
  32. package/dist/electron/main.js +417 -133
  33. package/dist/electron/modules/accessibility/macos-provider.d.ts +8 -0
  34. package/dist/electron/modules/accessibility/macos-provider.d.ts.map +1 -0
  35. package/dist/electron/modules/accessibility/macos-provider.js +94 -0
  36. package/dist/electron/modules/accessibility/macos-provider.js.map +1 -0
  37. package/dist/electron/modules/accessibility/provider.d.ts +12 -0
  38. package/dist/electron/modules/accessibility/provider.d.ts.map +1 -0
  39. package/dist/electron/modules/accessibility/provider.js +52 -0
  40. package/dist/electron/modules/accessibility/provider.js.map +1 -0
  41. package/dist/electron/modules/accessibility/types.d.ts +63 -0
  42. package/dist/electron/modules/accessibility/types.d.ts.map +1 -0
  43. package/dist/electron/modules/accessibility/types.js +6 -0
  44. package/dist/electron/modules/accessibility/types.js.map +1 -0
  45. package/dist/electron/modules/accessibility/windows-provider.d.ts +8 -0
  46. package/dist/electron/modules/accessibility/windows-provider.d.ts.map +1 -0
  47. package/dist/electron/modules/accessibility/windows-provider.js +85 -0
  48. package/dist/electron/modules/accessibility/windows-provider.js.map +1 -0
  49. package/dist/electron/modules/api-server.d.ts +4 -1
  50. package/dist/electron/modules/api-server.d.ts.map +1 -1
  51. package/dist/electron/modules/api-server.js +1349 -219
  52. package/dist/electron/modules/api-server.js.map +1 -1
  53. package/dist/electron/modules/auth.d.ts +14 -0
  54. package/dist/electron/modules/auth.d.ts.map +1 -1
  55. package/dist/electron/modules/auth.js +43 -0
  56. package/dist/electron/modules/auth.js.map +1 -1
  57. package/dist/electron/modules/azure-speech-realtime.d.ts.map +1 -1
  58. package/dist/electron/modules/azure-speech-realtime.js +56 -0
  59. package/dist/electron/modules/azure-speech-realtime.js.map +1 -1
  60. package/dist/electron/modules/capture.d.ts +8 -0
  61. package/dist/electron/modules/capture.d.ts.map +1 -1
  62. package/dist/electron/modules/capture.js +33 -0
  63. package/dist/electron/modules/capture.js.map +1 -1
  64. package/dist/electron/modules/compose-screenshots.d.ts +8 -0
  65. package/dist/electron/modules/compose-screenshots.d.ts.map +1 -0
  66. package/dist/electron/modules/compose-screenshots.js +86 -0
  67. package/dist/electron/modules/compose-screenshots.js.map +1 -0
  68. package/dist/electron/modules/context-menu-detect.d.ts +47 -0
  69. package/dist/electron/modules/context-menu-detect.d.ts.map +1 -0
  70. package/dist/electron/modules/context-menu-detect.js +272 -0
  71. package/dist/electron/modules/context-menu-detect.js.map +1 -0
  72. package/dist/electron/modules/dictation.d.ts.map +1 -1
  73. package/dist/electron/modules/dictation.js +12 -7
  74. package/dist/electron/modules/dictation.js.map +1 -1
  75. package/dist/electron/modules/gif-util.d.ts +9 -0
  76. package/dist/electron/modules/gif-util.d.ts.map +1 -0
  77. package/dist/electron/modules/gif-util.js +63 -0
  78. package/dist/electron/modules/gif-util.js.map +1 -0
  79. package/dist/electron/modules/gui-automation-errors.d.ts +11 -0
  80. package/dist/electron/modules/gui-automation-errors.d.ts.map +1 -0
  81. package/dist/electron/modules/gui-automation-errors.js +79 -0
  82. package/dist/electron/modules/gui-automation-errors.js.map +1 -0
  83. package/dist/electron/modules/gui-automation-telemetry.d.ts +38 -0
  84. package/dist/electron/modules/gui-automation-telemetry.d.ts.map +1 -0
  85. package/dist/electron/modules/gui-automation-telemetry.js +200 -0
  86. package/dist/electron/modules/gui-automation-telemetry.js.map +1 -0
  87. package/dist/electron/modules/gui-automation.d.ts +1143 -0
  88. package/dist/electron/modules/gui-automation.d.ts.map +1 -0
  89. package/dist/electron/modules/gui-automation.js +8769 -0
  90. package/dist/electron/modules/gui-automation.js.map +1 -0
  91. package/dist/electron/modules/hotkeys.d.ts +2 -1
  92. package/dist/electron/modules/hotkeys.d.ts.map +1 -1
  93. package/dist/electron/modules/hotkeys.js +25 -1
  94. package/dist/electron/modules/hotkeys.js.map +1 -1
  95. package/dist/electron/modules/human-input/index.d.ts +35 -0
  96. package/dist/electron/modules/human-input/index.d.ts.map +1 -0
  97. package/dist/electron/modules/human-input/index.js +163 -0
  98. package/dist/electron/modules/human-input/index.js.map +1 -0
  99. package/dist/electron/modules/human-input/keyboard/timing.d.ts +38 -0
  100. package/dist/electron/modules/human-input/keyboard/timing.d.ts.map +1 -0
  101. package/dist/electron/modules/human-input/keyboard/timing.js +57 -0
  102. package/dist/electron/modules/human-input/keyboard/timing.js.map +1 -0
  103. package/dist/electron/modules/human-input/mouse/path.d.ts +24 -0
  104. package/dist/electron/modules/human-input/mouse/path.d.ts.map +1 -0
  105. package/dist/electron/modules/human-input/mouse/path.js +80 -0
  106. package/dist/electron/modules/human-input/mouse/path.js.map +1 -0
  107. package/dist/electron/modules/human-input/mouse/velocity.d.ts +48 -0
  108. package/dist/electron/modules/human-input/mouse/velocity.d.ts.map +1 -0
  109. package/dist/electron/modules/human-input/mouse/velocity.js +93 -0
  110. package/dist/electron/modules/human-input/mouse/velocity.js.map +1 -0
  111. package/dist/electron/modules/human-input/profiles.d.ts +90 -0
  112. package/dist/electron/modules/human-input/profiles.d.ts.map +1 -0
  113. package/dist/electron/modules/human-input/profiles.js +124 -0
  114. package/dist/electron/modules/human-input/profiles.js.map +1 -0
  115. package/dist/electron/modules/human-input/rng.d.ts +16 -0
  116. package/dist/electron/modules/human-input/rng.d.ts.map +1 -0
  117. package/dist/electron/modules/human-input/rng.js +101 -0
  118. package/dist/electron/modules/human-input/rng.js.map +1 -0
  119. package/dist/electron/modules/human-input/salt.d.ts +15 -0
  120. package/dist/electron/modules/human-input/salt.d.ts.map +1 -0
  121. package/dist/electron/modules/human-input/salt.js +48 -0
  122. package/dist/electron/modules/human-input/salt.js.map +1 -0
  123. package/dist/electron/modules/image-utils.d.ts +20 -0
  124. package/dist/electron/modules/image-utils.d.ts.map +1 -0
  125. package/dist/electron/modules/image-utils.js +80 -0
  126. package/dist/electron/modules/image-utils.js.map +1 -0
  127. package/dist/electron/modules/ollama/capability.d.ts +32 -0
  128. package/dist/electron/modules/ollama/capability.d.ts.map +1 -0
  129. package/dist/electron/modules/ollama/capability.js +117 -0
  130. package/dist/electron/modules/ollama/capability.js.map +1 -0
  131. package/dist/electron/modules/ollama/client.d.ts +14 -0
  132. package/dist/electron/modules/ollama/client.d.ts.map +1 -0
  133. package/dist/electron/modules/ollama/client.js +134 -0
  134. package/dist/electron/modules/ollama/client.js.map +1 -0
  135. package/dist/electron/modules/ollama/detector.d.ts +29 -0
  136. package/dist/electron/modules/ollama/detector.d.ts.map +1 -0
  137. package/dist/electron/modules/ollama/detector.js +177 -0
  138. package/dist/electron/modules/ollama/detector.js.map +1 -0
  139. package/dist/electron/modules/ollama/dispatcher.d.ts +36 -0
  140. package/dist/electron/modules/ollama/dispatcher.d.ts.map +1 -0
  141. package/dist/electron/modules/ollama/dispatcher.js +97 -0
  142. package/dist/electron/modules/ollama/dispatcher.js.map +1 -0
  143. package/dist/electron/modules/ollama/router.d.ts +51 -0
  144. package/dist/electron/modules/ollama/router.d.ts.map +1 -0
  145. package/dist/electron/modules/ollama/router.js +201 -0
  146. package/dist/electron/modules/ollama/router.js.map +1 -0
  147. package/dist/electron/modules/pin-window.d.ts.map +1 -1
  148. package/dist/electron/modules/pin-window.js +2 -1
  149. package/dist/electron/modules/pin-window.js.map +1 -1
  150. package/dist/electron/modules/platform/dpi.d.ts +2 -0
  151. package/dist/electron/modules/platform/dpi.d.ts.map +1 -0
  152. package/dist/electron/modules/platform/dpi.js +48 -0
  153. package/dist/electron/modules/platform/dpi.js.map +1 -0
  154. package/dist/electron/modules/platform/errors.d.ts +13 -0
  155. package/dist/electron/modules/platform/errors.d.ts.map +1 -0
  156. package/dist/electron/modules/platform/errors.js +36 -0
  157. package/dist/electron/modules/platform/errors.js.map +1 -0
  158. package/dist/electron/modules/platform/index.d.ts +24 -0
  159. package/dist/electron/modules/platform/index.d.ts.map +1 -0
  160. package/dist/electron/modules/platform/index.js +133 -0
  161. package/dist/electron/modules/platform/index.js.map +1 -0
  162. package/dist/electron/modules/platform/interfaces.d.ts +140 -0
  163. package/dist/electron/modules/platform/interfaces.d.ts.map +1 -0
  164. package/dist/electron/modules/platform/interfaces.js +14 -0
  165. package/dist/electron/modules/platform/interfaces.js.map +1 -0
  166. package/dist/electron/modules/platform/macos/ax.d.ts +15 -0
  167. package/dist/electron/modules/platform/macos/ax.d.ts.map +1 -0
  168. package/dist/electron/modules/platform/macos/ax.js +222 -0
  169. package/dist/electron/modules/platform/macos/ax.js.map +1 -0
  170. package/dist/electron/modules/platform/macos/capture.d.ts +14 -0
  171. package/dist/electron/modules/platform/macos/capture.d.ts.map +1 -0
  172. package/dist/electron/modules/platform/macos/capture.js +106 -0
  173. package/dist/electron/modules/platform/macos/capture.js.map +1 -0
  174. package/dist/electron/modules/platform/macos/input.d.ts +16 -0
  175. package/dist/electron/modules/platform/macos/input.d.ts.map +1 -0
  176. package/dist/electron/modules/platform/macos/input.js +342 -0
  177. package/dist/electron/modules/platform/macos/input.js.map +1 -0
  178. package/dist/electron/modules/platform/macos/launch.d.ts +10 -0
  179. package/dist/electron/modules/platform/macos/launch.d.ts.map +1 -0
  180. package/dist/electron/modules/platform/macos/launch.js +114 -0
  181. package/dist/electron/modules/platform/macos/launch.js.map +1 -0
  182. package/dist/electron/modules/platform/macos/session.d.ts +8 -0
  183. package/dist/electron/modules/platform/macos/session.d.ts.map +1 -0
  184. package/dist/electron/modules/platform/macos/session.js +17 -0
  185. package/dist/electron/modules/platform/macos/session.js.map +1 -0
  186. package/dist/electron/modules/platform/macos/window.d.ts +31 -0
  187. package/dist/electron/modules/platform/macos/window.d.ts.map +1 -0
  188. package/dist/electron/modules/platform/macos/window.js +271 -0
  189. package/dist/electron/modules/platform/macos/window.js.map +1 -0
  190. package/dist/electron/modules/platform/shared.d.ts +10 -0
  191. package/dist/electron/modules/platform/shared.d.ts.map +1 -0
  192. package/dist/electron/modules/platform/shared.js +201 -0
  193. package/dist/electron/modules/platform/shared.js.map +1 -0
  194. package/dist/electron/modules/platform/types.d.ts +182 -0
  195. package/dist/electron/modules/platform/types.d.ts.map +1 -0
  196. package/dist/electron/modules/platform/types.js +24 -0
  197. package/dist/electron/modules/platform/types.js.map +1 -0
  198. package/dist/electron/modules/platform/windows/ax.d.ts +15 -0
  199. package/dist/electron/modules/platform/windows/ax.d.ts.map +1 -0
  200. package/dist/electron/modules/platform/windows/ax.js +277 -0
  201. package/dist/electron/modules/platform/windows/ax.js.map +1 -0
  202. package/dist/electron/modules/platform/windows/capture.d.ts +14 -0
  203. package/dist/electron/modules/platform/windows/capture.d.ts.map +1 -0
  204. package/dist/electron/modules/platform/windows/capture.js +115 -0
  205. package/dist/electron/modules/platform/windows/capture.js.map +1 -0
  206. package/dist/electron/modules/platform/windows/input.d.ts +17 -0
  207. package/dist/electron/modules/platform/windows/input.d.ts.map +1 -0
  208. package/dist/electron/modules/platform/windows/input.js +422 -0
  209. package/dist/electron/modules/platform/windows/input.js.map +1 -0
  210. package/dist/electron/modules/platform/windows/launch.d.ts +10 -0
  211. package/dist/electron/modules/platform/windows/launch.d.ts.map +1 -0
  212. package/dist/electron/modules/platform/windows/launch.js +185 -0
  213. package/dist/electron/modules/platform/windows/launch.js.map +1 -0
  214. package/dist/electron/modules/platform/windows/session.d.ts +8 -0
  215. package/dist/electron/modules/platform/windows/session.d.ts.map +1 -0
  216. package/dist/electron/modules/platform/windows/session.js +87 -0
  217. package/dist/electron/modules/platform/windows/session.js.map +1 -0
  218. package/dist/electron/modules/platform/windows/tray.d.ts +13 -0
  219. package/dist/electron/modules/platform/windows/tray.d.ts.map +1 -0
  220. package/dist/electron/modules/platform/windows/tray.js +390 -0
  221. package/dist/electron/modules/platform/windows/tray.js.map +1 -0
  222. package/dist/electron/modules/platform/windows/window.d.ts +30 -0
  223. package/dist/electron/modules/platform/windows/window.d.ts.map +1 -0
  224. package/dist/electron/modules/platform/windows/window.js +444 -0
  225. package/dist/electron/modules/platform/windows/window.js.map +1 -0
  226. package/dist/electron/modules/recording/providers/change-detect-shared-wrapper.d.ts +15 -0
  227. package/dist/electron/modules/recording/providers/change-detect-shared-wrapper.d.ts.map +1 -0
  228. package/dist/electron/modules/recording/providers/change-detect-shared-wrapper.js +62 -0
  229. package/dist/electron/modules/recording/providers/change-detect-shared-wrapper.js.map +1 -0
  230. package/dist/electron/modules/recording/providers/provider-factory.d.ts.map +1 -1
  231. package/dist/electron/modules/recording/providers/provider-factory.js +13 -7
  232. package/dist/electron/modules/recording/providers/provider-factory.js.map +1 -1
  233. package/dist/electron/modules/scroll-calibration.d.ts +152 -0
  234. package/dist/electron/modules/scroll-calibration.d.ts.map +1 -0
  235. package/dist/electron/modules/scroll-calibration.js +271 -0
  236. package/dist/electron/modules/scroll-calibration.js.map +1 -0
  237. package/dist/electron/modules/scroll-capture.d.ts +3 -1
  238. package/dist/electron/modules/scroll-capture.d.ts.map +1 -1
  239. package/dist/electron/modules/scroll-capture.js +21 -72
  240. package/dist/electron/modules/scroll-capture.js.map +1 -1
  241. package/dist/electron/modules/sequence-locate.d.ts +126 -0
  242. package/dist/electron/modules/sequence-locate.d.ts.map +1 -0
  243. package/dist/electron/modules/sequence-locate.js +356 -0
  244. package/dist/electron/modules/sequence-locate.js.map +1 -0
  245. package/dist/electron/modules/store.d.ts +15 -56
  246. package/dist/electron/modules/store.d.ts.map +1 -1
  247. package/dist/electron/modules/store.js +84 -58
  248. package/dist/electron/modules/store.js.map +1 -1
  249. package/dist/electron/modules/stt/capability-probe.d.ts +67 -0
  250. package/dist/electron/modules/stt/capability-probe.d.ts.map +1 -0
  251. package/dist/electron/modules/stt/capability-probe.js +331 -0
  252. package/dist/electron/modules/stt/capability-probe.js.map +1 -0
  253. package/dist/electron/modules/stt/macos-engine.d.ts +20 -0
  254. package/dist/electron/modules/stt/macos-engine.d.ts.map +1 -0
  255. package/dist/electron/modules/stt/macos-engine.js +231 -0
  256. package/dist/electron/modules/stt/macos-engine.js.map +1 -0
  257. package/dist/electron/modules/stt/model-manager.d.ts +87 -0
  258. package/dist/electron/modules/stt/model-manager.d.ts.map +1 -0
  259. package/dist/electron/modules/stt/model-manager.js +321 -0
  260. package/dist/electron/modules/stt/model-manager.js.map +1 -0
  261. package/dist/electron/modules/stt/router.d.ts +35 -0
  262. package/dist/electron/modules/stt/router.d.ts.map +1 -0
  263. package/dist/electron/modules/stt/router.js +232 -0
  264. package/dist/electron/modules/stt/router.js.map +1 -0
  265. package/dist/electron/modules/stt/sherpa-engine.d.ts +43 -0
  266. package/dist/electron/modules/stt/sherpa-engine.d.ts.map +1 -0
  267. package/dist/electron/modules/stt/sherpa-engine.js +521 -0
  268. package/dist/electron/modules/stt/sherpa-engine.js.map +1 -0
  269. package/dist/electron/modules/stt/types.d.ts +72 -0
  270. package/dist/electron/modules/stt/types.d.ts.map +1 -0
  271. package/dist/electron/modules/stt/types.js +16 -0
  272. package/dist/electron/modules/stt/types.js.map +1 -0
  273. package/dist/electron/modules/stt/winrt-engine.d.ts +20 -0
  274. package/dist/electron/modules/stt/winrt-engine.d.ts.map +1 -0
  275. package/dist/electron/modules/stt/winrt-engine.js +238 -0
  276. package/dist/electron/modules/stt/winrt-engine.js.map +1 -0
  277. package/dist/electron/modules/template-match.d.ts +62 -0
  278. package/dist/electron/modules/template-match.d.ts.map +1 -0
  279. package/dist/electron/modules/template-match.js +205 -0
  280. package/dist/electron/modules/template-match.js.map +1 -0
  281. package/dist/electron/modules/tray.d.ts +2 -0
  282. package/dist/electron/modules/tray.d.ts.map +1 -1
  283. package/dist/electron/modules/tray.js +136 -8
  284. package/dist/electron/modules/tray.js.map +1 -1
  285. package/dist/electron/modules/undo-stack.d.ts +22 -0
  286. package/dist/electron/modules/undo-stack.d.ts.map +1 -0
  287. package/dist/electron/modules/undo-stack.js +41 -0
  288. package/dist/electron/modules/undo-stack.js.map +1 -0
  289. package/dist/electron/modules/watchers/active-window-watcher.d.ts +5 -0
  290. package/dist/electron/modules/watchers/active-window-watcher.d.ts.map +1 -0
  291. package/dist/electron/modules/watchers/active-window-watcher.js +152 -0
  292. package/dist/electron/modules/watchers/active-window-watcher.js.map +1 -0
  293. package/dist/electron/modules/watchers/clipboard-watcher.d.ts +5 -0
  294. package/dist/electron/modules/watchers/clipboard-watcher.d.ts.map +1 -0
  295. package/dist/electron/modules/watchers/clipboard-watcher.js +90 -0
  296. package/dist/electron/modules/watchers/clipboard-watcher.js.map +1 -0
  297. package/dist/electron/modules/watchers/file-watcher.d.ts +5 -0
  298. package/dist/electron/modules/watchers/file-watcher.d.ts.map +1 -0
  299. package/dist/electron/modules/watchers/file-watcher.js +91 -0
  300. package/dist/electron/modules/watchers/file-watcher.js.map +1 -0
  301. package/dist/electron/modules/watchers/registry.d.ts +34 -0
  302. package/dist/electron/modules/watchers/registry.d.ts.map +1 -0
  303. package/dist/electron/modules/watchers/registry.js +108 -0
  304. package/dist/electron/modules/watchers/registry.js.map +1 -0
  305. package/dist/electron/modules/watchers/screen-region-service.d.ts +18 -0
  306. package/dist/electron/modules/watchers/screen-region-service.d.ts.map +1 -0
  307. package/dist/electron/modules/watchers/screen-region-service.js +126 -0
  308. package/dist/electron/modules/watchers/screen-region-service.js.map +1 -0
  309. package/dist/electron/modules/watchers/screen-region-watcher.d.ts +6 -0
  310. package/dist/electron/modules/watchers/screen-region-watcher.d.ts.map +1 -0
  311. package/dist/electron/modules/watchers/screen-region-watcher.js +70 -0
  312. package/dist/electron/modules/watchers/screen-region-watcher.js.map +1 -0
  313. package/dist/electron/modules/window-activate.d.ts +103 -0
  314. package/dist/electron/modules/window-activate.d.ts.map +1 -0
  315. package/dist/electron/modules/window-activate.js +630 -0
  316. package/dist/electron/modules/window-activate.js.map +1 -0
  317. package/dist/electron/modules/window-input.d.ts +43 -0
  318. package/dist/electron/modules/window-input.d.ts.map +1 -0
  319. package/dist/electron/modules/window-input.js +623 -0
  320. package/dist/electron/modules/window-input.js.map +1 -0
  321. package/dist/electron/modules/window-resolver.d.ts +35 -0
  322. package/dist/electron/modules/window-resolver.d.ts.map +1 -0
  323. package/dist/electron/modules/window-resolver.js +210 -0
  324. package/dist/electron/modules/window-resolver.js.map +1 -0
  325. package/dist/headless/electron/core/input-injection/index.js +30 -0
  326. package/dist/headless/electron/core/input-injection/macos.js +13 -0
  327. package/dist/headless/electron/core/input-injection/windows.js +118 -0
  328. package/dist/headless/electron/core/json-store.js +61 -47
  329. package/dist/headless/electron/core/serialize-schema.js +88 -0
  330. package/dist/headless/electron/core/settings-schema.js +1356 -0
  331. package/dist/headless/electron/logger.js +22 -8
  332. package/dist/headless/electron/modules/accessibility/macos-provider.js +93 -0
  333. package/dist/headless/electron/modules/accessibility/provider.js +51 -0
  334. package/dist/headless/electron/modules/accessibility/types.js +5 -0
  335. package/dist/headless/electron/modules/accessibility/windows-provider.js +84 -0
  336. package/dist/headless/electron/modules/api-server.js +1349 -219
  337. package/dist/headless/electron/modules/auth.js +43 -0
  338. package/dist/headless/electron/modules/azure-speech-realtime.js +56 -0
  339. package/dist/headless/electron/modules/capture.js +33 -0
  340. package/dist/headless/electron/modules/context-menu-detect.js +271 -0
  341. package/dist/headless/electron/modules/dictation.js +12 -7
  342. package/dist/headless/electron/modules/gui-automation-errors.js +78 -0
  343. package/dist/headless/electron/modules/gui-automation-telemetry.js +199 -0
  344. package/dist/headless/electron/modules/gui-automation.js +8768 -0
  345. package/dist/headless/electron/modules/human-input/keyboard/timing.js +56 -0
  346. package/dist/headless/electron/modules/human-input/mouse/path.js +79 -0
  347. package/dist/headless/electron/modules/human-input/mouse/velocity.js +92 -0
  348. package/dist/headless/electron/modules/human-input/profiles.js +123 -0
  349. package/dist/headless/electron/modules/human-input/rng.js +100 -0
  350. package/dist/headless/electron/modules/human-input/salt.js +47 -0
  351. package/dist/headless/electron/modules/image-utils.js +79 -0
  352. package/dist/headless/electron/modules/ollama/capability.js +116 -0
  353. package/dist/headless/electron/modules/ollama/client.js +133 -0
  354. package/dist/headless/electron/modules/ollama/detector.js +176 -0
  355. package/dist/headless/electron/modules/ollama/dispatcher.js +96 -0
  356. package/dist/headless/electron/modules/ollama/router.js +200 -0
  357. package/dist/headless/electron/modules/platform/dpi.js +47 -0
  358. package/dist/headless/electron/modules/platform/errors.js +35 -0
  359. package/dist/headless/electron/modules/platform/index.js +132 -0
  360. package/dist/headless/electron/modules/platform/interfaces.js +13 -0
  361. package/dist/headless/electron/modules/platform/macos/ax.js +221 -0
  362. package/dist/headless/electron/modules/platform/macos/capture.js +105 -0
  363. package/dist/headless/electron/modules/platform/macos/input.js +341 -0
  364. package/dist/headless/electron/modules/platform/macos/launch.js +113 -0
  365. package/dist/headless/electron/modules/platform/macos/session.js +16 -0
  366. package/dist/headless/electron/modules/platform/macos/window.js +270 -0
  367. package/dist/headless/electron/modules/platform/shared.js +200 -0
  368. package/dist/headless/electron/modules/platform/types.js +23 -0
  369. package/dist/headless/electron/modules/platform/windows/ax.js +276 -0
  370. package/dist/headless/electron/modules/platform/windows/capture.js +114 -0
  371. package/dist/headless/electron/modules/platform/windows/input.js +421 -0
  372. package/dist/headless/electron/modules/platform/windows/launch.js +184 -0
  373. package/dist/headless/electron/modules/platform/windows/session.js +86 -0
  374. package/dist/headless/electron/modules/platform/windows/tray.js +389 -0
  375. package/dist/headless/electron/modules/platform/windows/window.js +443 -0
  376. package/dist/headless/electron/modules/recording/providers/change-detect-shared-wrapper.js +61 -0
  377. package/dist/headless/electron/modules/recording/providers/provider-factory.js +13 -7
  378. package/dist/headless/electron/modules/scroll-calibration.js +270 -0
  379. package/dist/headless/electron/modules/sequence-locate.js +355 -0
  380. package/dist/headless/electron/modules/store.js +84 -58
  381. package/dist/headless/electron/modules/stt/capability-probe.js +330 -0
  382. package/dist/headless/electron/modules/stt/macos-engine.js +230 -0
  383. package/dist/headless/electron/modules/stt/model-manager.js +320 -0
  384. package/dist/headless/electron/modules/stt/router.js +231 -0
  385. package/dist/headless/electron/modules/stt/sherpa-engine.js +520 -0
  386. package/dist/headless/electron/modules/stt/types.js +15 -0
  387. package/dist/headless/electron/modules/stt/winrt-engine.js +237 -0
  388. package/dist/headless/electron/modules/template-match.js +204 -0
  389. package/dist/headless/electron/modules/undo-stack.js +40 -0
  390. package/dist/headless/electron/modules/watchers/active-window-watcher.js +151 -0
  391. package/dist/headless/electron/modules/watchers/clipboard-watcher.js +89 -0
  392. package/dist/headless/electron/modules/watchers/file-watcher.js +90 -0
  393. package/dist/headless/electron/modules/watchers/registry.js +107 -0
  394. package/dist/headless/electron/modules/watchers/screen-region-service.js +125 -0
  395. package/dist/headless/electron/modules/watchers/screen-region-watcher.js +69 -0
  396. package/dist/headless/electron/modules/window-activate.js +629 -0
  397. package/dist/headless/electron/modules/window-input.js +622 -0
  398. package/dist/headless/electron/modules/window-resolver.js +209 -0
  399. package/dist/headless/headless/cli.js +60 -7
  400. package/dist/headless/headless/config-cmd.js +306 -0
  401. package/dist/headless/headless/doctor.js +599 -0
  402. package/dist/headless/headless/ollama-cmd.js +211 -0
  403. package/dist/headless/headless/platform-headless.js +13 -1
  404. package/dist/headless/headless/server.js +38 -2
  405. package/dist/headless/headless/stt-cmd.js +213 -0
  406. package/dist/headless/headless/tui/index.mjs +7 -0
  407. package/dist/headless/headless/tui/plain-dump.js +41 -0
  408. package/dist/headless/headless/tui/settings-app.mjs +744 -0
  409. package/dist/headless/headless/tui/setup-wizard.mjs +257 -0
  410. package/dist/headless/headless/tui-bridge.js +80 -0
  411. package/dist/headless/shared/constants.js +3 -1
  412. package/dist/shared/constants.d.ts +2 -0
  413. package/dist/shared/constants.d.ts.map +1 -1
  414. package/dist/shared/constants.js +3 -1
  415. package/dist/shared/constants.js.map +1 -1
  416. package/dist/shared/types.d.ts +8 -0
  417. package/dist/shared/types.d.ts.map +1 -1
  418. package/mcp-server/dist/api-client.js +257 -6
  419. package/mcp-server/dist/index.js +1566 -46
  420. package/mcp-server/dist/project-sense.js +161 -0
  421. package/mcp-server/dist/tool-categories.js +161 -0
  422. package/mcp-server/package.json +8 -2
  423. package/package.json +33 -5
@@ -0,0 +1,629 @@
1
+ "use strict";
2
+ // Cross-platform window activation — extracted from capture-fullscreen-image
3
+ // so superbased_focus_window can actually focus a window (vs the v1 shipped
4
+ // behavior of returning the matched window without activating it).
5
+ //
6
+ // Returns diagnostic info so callers can verify whether the OS actually
7
+ // switched foreground (it sometimes silently doesn't on VS Code / Electron
8
+ // apps that aggressively reclaim focus). focus_window itself doesn't
9
+ // restore — its contract is to leave the new window focused.
10
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ var desc = Object.getOwnPropertyDescriptor(m, k);
13
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
+ desc = { enumerable: true, get: function() { return m[k]; } };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }) : (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ o[k2] = m[k];
20
+ }));
21
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
22
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
23
+ }) : function(o, v) {
24
+ o["default"] = v;
25
+ });
26
+ var __importStar = (this && this.__importStar) || (function () {
27
+ var ownKeys = function(o) {
28
+ ownKeys = Object.getOwnPropertyNames || function (o) {
29
+ var ar = [];
30
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
+ return ar;
32
+ };
33
+ return ownKeys(o);
34
+ };
35
+ return function (mod) {
36
+ if (mod && mod.__esModule) return mod;
37
+ var result = {};
38
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
+ __setModuleDefault(result, mod);
40
+ return result;
41
+ };
42
+ })();
43
+ var __importDefault = (this && this.__importDefault) || function (mod) {
44
+ return (mod && mod.__esModule) ? mod : { "default": mod };
45
+ };
46
+ Object.defineProperty(exports, "__esModule", { value: true });
47
+ exports.activateWindow = activateWindow;
48
+ exports.restoreWindow = restoreWindow;
49
+ exports.getCurrentForegroundHwnd = getCurrentForegroundHwnd;
50
+ exports.restoreWindowVerified = restoreWindowVerified;
51
+ exports.captureWindowBackgroundWindows = captureWindowBackgroundWindows;
52
+ exports.activateWindowSimple = activateWindowSimple;
53
+ exports.withActivatedWindow = withActivatedWindow;
54
+ const fs = __importStar(require("fs"));
55
+ const os = __importStar(require("os"));
56
+ const path = __importStar(require("path"));
57
+ const childProcess = __importStar(require("child_process"));
58
+ const logger_1 = __importDefault(require("../logger"));
59
+ /**
60
+ * Bring `target` to the foreground. Returns diagnostic info including a
61
+ * `verified` flag that, on Windows, reports whether GetForegroundWindow()
62
+ * matches the requested hwnd after activation. Use this to detect when
63
+ * activation silently failed (focus stolen back by another app).
64
+ */
65
+ async function activateWindow(target) {
66
+ if (process.platform === 'win32') {
67
+ return activateWindowsHwndWithVerify(target);
68
+ }
69
+ if (process.platform === 'darwin') {
70
+ const previous = activateMacApp(target);
71
+ return { ok: true, previous, attempted: 1 };
72
+ }
73
+ // Linux: best-effort via wmctrl
74
+ const previous = activateLinux(target);
75
+ return { ok: true, previous, attempted: 1 };
76
+ }
77
+ async function restoreWindow(previous) {
78
+ if (!previous || previous === '0')
79
+ return;
80
+ if (process.platform === 'win32') {
81
+ await restoreWindowsHwnd(previous);
82
+ }
83
+ else if (process.platform === 'darwin') {
84
+ await restoreMacApp(previous);
85
+ }
86
+ // Linux: no-op for now
87
+ }
88
+ /**
89
+ * Capture the current foreground window's hwnd (Windows only). Returns
90
+ * undefined on other platforms or if the probe fails. Use this BEFORE a
91
+ * scoped activation so you can restore to the real original foreground
92
+ * regardless of what happens to `diag.previous` during retries.
93
+ *
94
+ * Exported for callers that need to snapshot foreground before multiple
95
+ * activation attempts (the retry loop in activateWindow overwrites its
96
+ * own `previous` on each attempt — if attempt 1 succeeded, attempt 2's
97
+ * GetForegroundWindow() returns the TARGET hwnd, and the subsequent
98
+ * restore becomes a no-op pointing at the target itself).
99
+ */
100
+ function getCurrentForegroundHwnd() {
101
+ if (process.platform !== 'win32')
102
+ return undefined;
103
+ return getForegroundHwnd();
104
+ }
105
+ /**
106
+ * Restore + verify: multi-attempt SetForegroundWindow with the same
107
+ * AttachThreadInput trick activation uses, plus GetForegroundWindow
108
+ * verification after each attempt. Mirrors the robustness of
109
+ * activateWindow() in the reverse direction.
110
+ *
111
+ * Why a separate verified path instead of just calling restoreWindow()?
112
+ * SetForegroundWindow has the same idle-input-timeout restriction on
113
+ * the way back as on the way in. Without the AttachThreadInput wiggle,
114
+ * the OS silently refuses the focus change — the capture path then
115
+ * appears to work (image returns) but the agent window never actually
116
+ * regains focus, leaving the target window stuck in front.
117
+ *
118
+ * Returns whether verification confirmed the foreground flipped to
119
+ * `targetHwnd`. The caller can surface this in its diagnostic.
120
+ */
121
+ async function restoreWindowVerified(targetHwnd) {
122
+ if (!targetHwnd || targetHwnd === '0')
123
+ return { restored: false, attempts: 0 };
124
+ if (process.platform !== 'win32') {
125
+ // macOS / linux: reuse existing best-effort restore; we don't
126
+ // currently have a cheap foreground-hwnd-equivalent probe there.
127
+ try {
128
+ await restoreWindow(targetHwnd);
129
+ return { restored: true, attempts: 1 };
130
+ }
131
+ catch {
132
+ return { restored: false, attempts: 1 };
133
+ }
134
+ }
135
+ let attempts = 0;
136
+ let finalForeground;
137
+ for (let i = 0; i < 3; i++) {
138
+ attempts++;
139
+ try {
140
+ await restoreWindowsHwndWithAttach(targetHwnd);
141
+ }
142
+ catch { /* retry */ }
143
+ await new Promise((r) => setTimeout(r, 150));
144
+ finalForeground = getForegroundHwnd();
145
+ if (finalForeground === targetHwnd) {
146
+ return { restored: true, attempts, finalForeground };
147
+ }
148
+ await new Promise((r) => setTimeout(r, 100));
149
+ }
150
+ logger_1.default.warn(`[window-activate] restore did not verify after ${attempts} attempts. target hwnd=${targetHwnd}, final foreground=${finalForeground}`);
151
+ return { restored: false, attempts, finalForeground };
152
+ }
153
+ /**
154
+ * Windows-only restore that uses the AttachThreadInput + Alt-wiggle
155
+ * trick, matching what activateWindowsHwndOnce does. The vanilla
156
+ * restoreWindowsHwnd (below) uses only SetForegroundWindow + one
157
+ * Alt-key tap — works in about 70% of cases; this hardened variant
158
+ * pushes through the idle-time-hint restriction reliably.
159
+ *
160
+ * Important: does NOT call ShowWindow. The earlier version called
161
+ * ShowWindow(target, SW_RESTORE=9) "in case it was minimized
162
+ * meanwhile", which has a user-reported side effect: SW_RESTORE on a
163
+ * MAXIMIZED window un-maximizes it back to the last "normal" size.
164
+ * Agents would screenshot a target window, then the user's previously-
165
+ * maximized agent window would come back shrunk. Since we only ever
166
+ * restore to a window that was foreground moments ago (agent had the
167
+ * approval dialog), it's never minimized by definition — the
168
+ * ShowWindow call was unnecessary and harmful.
169
+ */
170
+ async function restoreWindowsHwndWithAttach(targetHwnd) {
171
+ const script = path.join(os.tmpdir(), 'superbased-restore-verified.ps1');
172
+ fs.writeFileSync(script, `
173
+ param([long]$TargetHwnd)
174
+ Add-Type -TypeDefinition @'
175
+ using System; using System.Runtime.InteropServices;
176
+ public class WinRestoreV {
177
+ [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
178
+ [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr h);
179
+ [DllImport("user32.dll")] public static extern bool BringWindowToTop(IntPtr h);
180
+ [DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr h, out uint pid);
181
+ [DllImport("kernel32.dll")] public static extern uint GetCurrentThreadId();
182
+ [DllImport("user32.dll")] public static extern bool AttachThreadInput(uint a, uint b, bool attach);
183
+ [DllImport("user32.dll")] public static extern void keybd_event(byte vk, byte scan, uint flags, UIntPtr extra);
184
+ public static void Restore(IntPtr target) {
185
+ IntPtr prev = GetForegroundWindow();
186
+ uint dummy;
187
+ uint fgThread = GetWindowThreadProcessId(prev, out dummy);
188
+ uint curThread = GetCurrentThreadId();
189
+ AttachThreadInput(curThread, fgThread, true);
190
+ // Tap Ctrl to reset Windows' foreground-lock timer so SetForegroundWindow
191
+ // succeeds from a non-foreground thread. Previously tapped Alt (VK_MENU
192
+ // 0x12) — which reliably unblocked the lock but also activated menu
193
+ // access-key mode on apps with menubars (Win11 Notepad showed F/E/V
194
+ // overlays AND cleared the editor's text selection, so follow-up Delete
195
+ // after Ctrl+A silently no-op'd). Ctrl (VK_CONTROL 0x11) counts as user
196
+ // input for the same purpose with zero menu side effects. Non-extended
197
+ // flags (0 press, 2 release) target left-Ctrl.
198
+ keybd_event(0x11, 0, 0, UIntPtr.Zero); // Ctrl press
199
+ keybd_event(0x11, 0, 2, UIntPtr.Zero); // Ctrl release
200
+ SetForegroundWindow(target);
201
+ BringWindowToTop(target);
202
+ AttachThreadInput(curThread, fgThread, false);
203
+ }
204
+ }
205
+ '@
206
+ [WinRestoreV]::Restore([IntPtr]::new($TargetHwnd))
207
+ `);
208
+ try {
209
+ childProcess.execSync(`powershell -ExecutionPolicy Bypass -File "${script}" -TargetHwnd ${targetHwnd}`, { timeout: 3000, stdio: 'pipe' });
210
+ }
211
+ finally {
212
+ try {
213
+ fs.unlinkSync(script);
214
+ }
215
+ catch { /* cleanup */ }
216
+ }
217
+ }
218
+ /**
219
+ * Background capture (Windows): PrintWindow with PW_RENDERFULLCONTENT.
220
+ *
221
+ * Captures the window's pixel content directly via WM_PRINT without
222
+ * bringing it to the foreground. Works regardless of z-order,
223
+ * occlusion, or minimize state. PW_RENDERFULLCONTENT (0x02) is the
224
+ * flag introduced in Win 8.1 that tells layered/DWM-composited windows
225
+ * (Electron, Chrome, modern UWP) to render their current frame — the
226
+ * pre-8.1 PW_CLIENTONLY (0x01) returned black on such windows.
227
+ *
228
+ * Returns the path to a PNG file on success, or null if the capture
229
+ * resulted in an empty/black bitmap (can happen for heavy GPU
230
+ * surfaces — some games, fullscreen video, hardware-accelerated
231
+ * browser tabs — which compose outside the window's own DC).
232
+ *
233
+ * Caller should fall back to the foreground-based capture path when
234
+ * this returns null.
235
+ */
236
+ async function captureWindowBackgroundWindows(hwnd) {
237
+ if (process.platform !== 'win32')
238
+ return null;
239
+ const outPath = path.join(os.tmpdir(), `superbased-bgcap-${process.pid}-${Date.now()}.png`);
240
+ const script = path.join(os.tmpdir(), `superbased-bgcap-${process.pid}-${Date.now()}.ps1`);
241
+ // PowerShell: enumerate size via GetWindowRect, create compatible DC +
242
+ // bitmap, PrintWindow with PW_RENDERFULLCONTENT, save PNG.
243
+ fs.writeFileSync(script, `
244
+ param([long]$Hwnd, [string]$OutPath)
245
+ Add-Type -AssemblyName System.Drawing
246
+ Add-Type -TypeDefinition @'
247
+ using System;
248
+ using System.Drawing;
249
+ using System.Drawing.Imaging;
250
+ using System.Runtime.InteropServices;
251
+
252
+ public class BgCap {
253
+ [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr h, out RECT r);
254
+ [DllImport("user32.dll")] public static extern bool PrintWindow(IntPtr h, IntPtr dc, uint flags);
255
+ [DllImport("user32.dll")] public static extern bool IsIconic(IntPtr h);
256
+ [DllImport("dwmapi.dll")] public static extern int DwmGetWindowAttribute(IntPtr h, uint attr, out RECT r, int size);
257
+ // DPI awareness — call at script start so GetWindowRect + PrintWindow
258
+ // return PHYSICAL pixels on high-DPI displays instead of logical. Without
259
+ // this, a 2560x1440 display at 150% scale returns frames at 1707x960 and
260
+ // our click coords (physical) don't match the screenshot pixels.
261
+ [DllImport("user32.dll")] public static extern IntPtr SetProcessDpiAwarenessContext(IntPtr awareness);
262
+ [DllImport("shcore.dll")] public static extern int SetProcessDpiAwareness(int awareness);
263
+
264
+ [StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left, Top, Right, Bottom; }
265
+
266
+ public const uint PW_RENDERFULLCONTENT = 0x00000002;
267
+ public const uint DWMWA_EXTENDED_FRAME_BOUNDS = 9;
268
+
269
+ public static bool IsBitmapMostlyBlack(Bitmap bmp) {
270
+ // Sample a 16x16 grid; if >95% of samples are near-black, treat as
271
+ // failure. Catches GPU-composited surfaces (some games, fullscreen
272
+ // video) where PrintWindow returns an empty/black bitmap.
273
+ int black = 0, total = 0;
274
+ for (int y = 0; y < 16; y++) {
275
+ for (int x = 0; x < 16; x++) {
276
+ int px = (int)(bmp.Width * (x / 16.0));
277
+ int py = (int)(bmp.Height * (y / 16.0));
278
+ if (px >= bmp.Width) px = bmp.Width - 1;
279
+ if (py >= bmp.Height) py = bmp.Height - 1;
280
+ Color c = bmp.GetPixel(px, py);
281
+ if (c.R < 8 && c.G < 8 && c.B < 8) black++;
282
+ total++;
283
+ }
284
+ }
285
+ return (black * 100) / total > 95;
286
+ }
287
+
288
+ public static int Capture(IntPtr h, string outPath) {
289
+ if (IsIconic(h)) return 2; // minimized — caller should fall back
290
+ RECT r;
291
+ if (!GetWindowRect(h, out r)) return 3;
292
+ int w = r.Right - r.Left, hpx = r.Bottom - r.Top;
293
+ if (w <= 0 || hpx <= 0) return 3;
294
+ Bitmap bmp = new Bitmap(w, hpx, PixelFormat.Format32bppArgb);
295
+ Graphics g = Graphics.FromImage(bmp);
296
+ IntPtr dc = g.GetHdc();
297
+ bool ok = PrintWindow(h, dc, PW_RENDERFULLCONTENT);
298
+ g.ReleaseHdc(dc);
299
+ g.Dispose();
300
+ if (!ok) { bmp.Dispose(); return 4; }
301
+ if (IsBitmapMostlyBlack(bmp)) { bmp.Dispose(); return 5; } // GPU surface
302
+ bmp.Save(outPath, ImageFormat.Png);
303
+ bmp.Dispose();
304
+ return 0;
305
+ }
306
+ }
307
+ '@
308
+ # Set DPI awareness BEFORE any GetWindowRect / PrintWindow calls so the
309
+ # capture returns physical pixels. PROCESS_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
310
+ # (= -4 as IntPtr) is Win10 1703+. Falls back to SetProcessDpiAwareness(2)
311
+ # on older Windows. Both calls are no-ops if already set (safe to double-call).
312
+ try {
313
+ [BgCap]::SetProcessDpiAwarenessContext([IntPtr]::new(-4)) | Out-Null
314
+ } catch {
315
+ try { [BgCap]::SetProcessDpiAwareness(2) | Out-Null } catch { }
316
+ }
317
+ $h = [IntPtr]::new($Hwnd)
318
+ $result = [BgCap]::Capture($h, $OutPath)
319
+ $result
320
+ `);
321
+ let exitCode = '99';
322
+ try {
323
+ exitCode = childProcess.execSync(`powershell -ExecutionPolicy Bypass -File "${script}" -Hwnd ${hwnd} -OutPath "${outPath}"`, { encoding: 'utf-8', timeout: 5000, stdio: 'pipe' }).trim();
324
+ }
325
+ catch (err) {
326
+ logger_1.default.warn(`[window-activate] PrintWindow capture failed: ${err.message}`);
327
+ }
328
+ finally {
329
+ try {
330
+ fs.unlinkSync(script);
331
+ }
332
+ catch { /* cleanup */ }
333
+ }
334
+ if (exitCode !== '0' || !fs.existsSync(outPath)) {
335
+ try {
336
+ fs.unlinkSync(outPath);
337
+ }
338
+ catch { /* cleanup */ }
339
+ return null;
340
+ }
341
+ // Probe size from the produced PNG. We could parse the PNG header
342
+ // directly but a cheap read through node-gyp bindings would be
343
+ // overkill for a log-only value — read once, return. Sharp is
344
+ // already a runtime dep on desktop; use it for dimensions.
345
+ let widthPx = 0, heightPx = 0;
346
+ try {
347
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
348
+ const sharp = require('sharp');
349
+ const meta = await sharp(outPath).metadata();
350
+ widthPx = meta.width || 0;
351
+ heightPx = meta.height || 0;
352
+ }
353
+ catch { /* dimensions optional */ }
354
+ return { path: outPath, widthPx, heightPx };
355
+ }
356
+ // Convenience for callers that just want the previous-foreground token (the
357
+ // pre-existing capture path expects this shape).
358
+ async function activateWindowSimple(target) {
359
+ const result = await activateWindow(target);
360
+ return result.previous || '';
361
+ }
362
+ async function withActivatedWindow(target, fn, opts) {
363
+ const restoreFocus = opts?.restoreFocus !== false;
364
+ const skipIfAlreadyForeground = opts?.skipIfAlreadyForeground !== false;
365
+ const paintDelayMs = opts?.paintDelayMs ?? 150;
366
+ const t0 = Date.now();
367
+ const timings = { actionMs: 0, totalMs: 0 };
368
+ // 1. Snapshot foreground BEFORE activation — this is the only value we
369
+ // can safely restore to. `activateWindow`'s retry loop can overwrite
370
+ // its own `previous` field on attempt 2+ when attempt 1 already moved
371
+ // foreground to the target.
372
+ const tSnap = Date.now();
373
+ const originalForeground = getCurrentForegroundHwnd();
374
+ timings.snapshotMs = Date.now() - tSnap;
375
+ // 2. Skip activation when target is already foreground — eliminates
376
+ // focus-flicker in the common "already focused" case.
377
+ const alreadyForeground = skipIfAlreadyForeground && !!target.hwnd && originalForeground === target.hwnd;
378
+ let diag;
379
+ if (alreadyForeground) {
380
+ diag = {
381
+ ok: true,
382
+ previous: originalForeground,
383
+ attempted: 0,
384
+ verified: true,
385
+ postForeground: originalForeground,
386
+ };
387
+ }
388
+ else {
389
+ const tAct = Date.now();
390
+ diag = await activateWindow(target);
391
+ timings.activateMs = Date.now() - tAct;
392
+ if (paintDelayMs > 0) {
393
+ const tPaint = Date.now();
394
+ await new Promise((r) => setTimeout(r, paintDelayMs));
395
+ timings.paintMs = Date.now() - tPaint;
396
+ }
397
+ }
398
+ // 3. Run the action — errors propagate, but restore still runs via finally.
399
+ let result;
400
+ let actionError;
401
+ const tFn = Date.now();
402
+ try {
403
+ result = await fn();
404
+ }
405
+ catch (err) {
406
+ actionError = err;
407
+ result = undefined;
408
+ }
409
+ timings.actionMs = Date.now() - tFn;
410
+ // 4. Restore if we activated and caller wants it. Prefer the pre-activation
411
+ // snapshot over diag.previous (the snapshot is the only definitely-correct
412
+ // original; diag.previous can be the target itself under retry races).
413
+ let restore = { restored: false, attempts: 0, skipped: true };
414
+ if (!alreadyForeground && restoreFocus) {
415
+ const restoreHwnd = (originalForeground && originalForeground !== target.hwnd)
416
+ ? originalForeground
417
+ : diag.previous;
418
+ if (restoreHwnd && restoreHwnd !== '0' && restoreHwnd !== target.hwnd) {
419
+ const tRestore = Date.now();
420
+ if (process.platform === 'win32') {
421
+ try {
422
+ const r = await restoreWindowVerified(restoreHwnd);
423
+ restore = { restored: r.restored, attempts: r.attempts, finalForeground: r.finalForeground };
424
+ }
425
+ catch {
426
+ restore = { restored: false, attempts: 1 };
427
+ }
428
+ }
429
+ else {
430
+ try {
431
+ await restoreWindow(restoreHwnd);
432
+ restore = { restored: true, attempts: 1 };
433
+ }
434
+ catch {
435
+ restore = { restored: false, attempts: 1 };
436
+ }
437
+ }
438
+ timings.restoreMs = Date.now() - tRestore;
439
+ }
440
+ }
441
+ timings.totalMs = Date.now() - t0;
442
+ if (actionError)
443
+ throw actionError;
444
+ return { result, diag, restore, timings };
445
+ }
446
+ // ── Windows ──
447
+ async function activateWindowsHwndWithVerify(target) {
448
+ const hwnd = target.hwnd;
449
+ let previous = '0';
450
+ let lastError;
451
+ let postForeground;
452
+ let attempted = 0;
453
+ // Up to 3 activation attempts — VS Code's TUI is known to re-assert focus
454
+ // shortly after a competing window claims foreground. Multi-shot pushes
455
+ // through that race.
456
+ for (let i = 0; i < 3; i++) {
457
+ attempted++;
458
+ try {
459
+ const result = activateWindowsHwndOnce(target);
460
+ previous = result.previous || previous;
461
+ lastError = result.error;
462
+ }
463
+ catch (err) {
464
+ lastError = err.message || String(err);
465
+ }
466
+ // settle then verify
467
+ await new Promise((r) => setTimeout(r, 200));
468
+ postForeground = getForegroundHwnd();
469
+ if (hwnd && postForeground === hwnd) {
470
+ return { ok: true, previous, attempted, verified: true, postForeground };
471
+ }
472
+ // brief pause before retry
473
+ await new Promise((r) => setTimeout(r, 100));
474
+ }
475
+ // Final verification — failed if we get here
476
+ logger_1.default.warn(`[window-activate] activation did not verify after ${attempted} attempts. target hwnd=${hwnd}, post foreground=${postForeground}, last error=${lastError}`);
477
+ return {
478
+ ok: !!previous && previous !== '0', // PowerShell ran successfully even if focus didn't stick
479
+ previous,
480
+ attempted,
481
+ verified: false,
482
+ postForeground,
483
+ error: lastError ?? `foreground did not switch to target hwnd ${hwnd} (final foreground was ${postForeground})`,
484
+ };
485
+ }
486
+ function getForegroundHwnd() {
487
+ try {
488
+ const out = childProcess.execSync(`powershell -ExecutionPolicy Bypass -Command "Add-Type -TypeDefinition 'using System;using System.Runtime.InteropServices;public class FG{[DllImport(\\"user32.dll\\")]public static extern IntPtr GetForegroundWindow();}'; [FG]::GetForegroundWindow().ToInt64()"`, { encoding: 'utf-8', timeout: 3000, stdio: 'pipe' });
489
+ return out.trim();
490
+ }
491
+ catch {
492
+ return undefined;
493
+ }
494
+ }
495
+ function activateWindowsHwndOnce(target) {
496
+ const hwnd = target.hwnd;
497
+ if (hwnd) {
498
+ const script = path.join(os.tmpdir(), 'superbased-activate.ps1');
499
+ // AttachThreadInput trick + Alt-key wiggle to bypass SetForegroundWindow
500
+ // restrictions when called from a non-foreground process. Returns the
501
+ // previous foreground hwnd as a long.
502
+ fs.writeFileSync(script, `
503
+ param([long]$TargetHwnd)
504
+ Add-Type -TypeDefinition @'
505
+ using System; using System.Runtime.InteropServices;
506
+ public class WinActivate {
507
+ [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
508
+ [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr h, int c);
509
+ [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr h);
510
+ [DllImport("user32.dll")] public static extern bool BringWindowToTop(IntPtr h);
511
+ [DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr h, out uint pid);
512
+ [DllImport("kernel32.dll")] public static extern uint GetCurrentThreadId();
513
+ [DllImport("user32.dll")] public static extern bool AttachThreadInput(uint a, uint b, bool attach);
514
+ [DllImport("user32.dll")] public static extern void keybd_event(byte vk, byte scan, uint flags, UIntPtr extra);
515
+ public static IntPtr Activate(IntPtr target) {
516
+ IntPtr prev = GetForegroundWindow();
517
+ uint dummy;
518
+ uint fgThread = GetWindowThreadProcessId(prev, out dummy);
519
+ uint curThread = GetCurrentThreadId();
520
+ AttachThreadInput(curThread, fgThread, true);
521
+ ShowWindow(target, 9);
522
+ // Ctrl-tap resets the foreground-lock timer without activating menu access
523
+ // keys on apps with menubars (Alt would, and Win11 Notepad in particular
524
+ // clears the text selection as a side effect). See WinRestoreV above.
525
+ keybd_event(0x11, 0, 0, UIntPtr.Zero);
526
+ keybd_event(0x11, 0, 2, UIntPtr.Zero);
527
+ SetForegroundWindow(target);
528
+ BringWindowToTop(target);
529
+ AttachThreadInput(curThread, fgThread, false);
530
+ return prev;
531
+ }
532
+ }
533
+ '@
534
+ $h = [IntPtr]::new($TargetHwnd)
535
+ $prev = [WinActivate]::Activate($h)
536
+ $prev.ToInt64()
537
+ `);
538
+ let prev = '0';
539
+ let err;
540
+ try {
541
+ prev = childProcess.execSync(`powershell -ExecutionPolicy Bypass -File "${script}" -TargetHwnd ${hwnd}`, { encoding: 'utf-8', timeout: 5000, stdio: 'pipe' }).trim();
542
+ }
543
+ catch (e) {
544
+ err = e.message || String(e);
545
+ }
546
+ try {
547
+ fs.unlinkSync(script);
548
+ }
549
+ catch { /* cleanup */ }
550
+ return { previous: prev, error: err };
551
+ }
552
+ // Fallback: AppActivate by title
553
+ const fallback = path.join(os.tmpdir(), 'superbased-activate-title.ps1');
554
+ fs.writeFileSync(fallback, `param([string]$Title)\n(New-Object -ComObject WScript.Shell).AppActivate($Title)\n`);
555
+ let fallbackErr;
556
+ try {
557
+ childProcess.execSync(`powershell -ExecutionPolicy Bypass -File "${fallback}" -Title "${target.name.replace(/"/g, '`"')}"`, { timeout: 3000, stdio: 'pipe' });
558
+ }
559
+ catch (e) {
560
+ fallbackErr = e.message || String(e);
561
+ }
562
+ try {
563
+ fs.unlinkSync(fallback);
564
+ }
565
+ catch { /* cleanup */ }
566
+ return { previous: '', error: fallbackErr };
567
+ }
568
+ async function restoreWindowsHwnd(previousHwnd) {
569
+ const script = path.join(os.tmpdir(), 'superbased-restore.ps1');
570
+ fs.writeFileSync(script, `
571
+ param([long]$Hwnd)
572
+ Add-Type -TypeDefinition @'
573
+ using System; using System.Runtime.InteropServices;
574
+ public class WinRestore {
575
+ [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr h);
576
+ [DllImport("user32.dll")] public static extern void keybd_event(byte vk, byte scan, uint flags, UIntPtr extra);
577
+ public static void Restore(IntPtr target) {
578
+ // Ctrl-tap (not Alt-tap) resets the foreground-lock timer without
579
+ // activating menu access keys. See WinRestoreV / WinActivate above for
580
+ // the full rationale.
581
+ keybd_event(0x11, 0, 0, UIntPtr.Zero);
582
+ keybd_event(0x11, 0, 2, UIntPtr.Zero);
583
+ SetForegroundWindow(target);
584
+ }
585
+ }
586
+ '@
587
+ [WinRestore]::Restore([IntPtr]::new($Hwnd))
588
+ `);
589
+ try {
590
+ childProcess.execSync(`powershell -ExecutionPolicy Bypass -File "${script}" -Hwnd ${previousHwnd}`, { timeout: 3000, stdio: 'pipe' });
591
+ }
592
+ catch { /* ignore */ }
593
+ try {
594
+ fs.unlinkSync(script);
595
+ }
596
+ catch { /* cleanup */ }
597
+ }
598
+ // ── macOS ──
599
+ function activateMacApp(target) {
600
+ // Window names from listWindows are "AppName - Window Title" — extract app
601
+ const appName = target.name.split(' - ')[0] || target.name;
602
+ let previous = '';
603
+ try {
604
+ previous = childProcess.execFileSync('osascript', ['-e', 'tell application "System Events" to get name of first process whose frontmost is true'], { encoding: 'utf-8', timeout: 3000, stdio: 'pipe' }).trim();
605
+ }
606
+ catch { /* ignore */ }
607
+ try {
608
+ childProcess.execFileSync('osascript', ['-e', `tell application "${appName.replace(/"/g, '\\"')}" to activate`], { timeout: 3000, stdio: 'pipe' });
609
+ }
610
+ catch { /* ignore */ }
611
+ return previous;
612
+ }
613
+ async function restoreMacApp(previousApp) {
614
+ if (!previousApp)
615
+ return;
616
+ try {
617
+ childProcess.execFileSync('osascript', ['-e', `tell application "${previousApp.replace(/"/g, '\\"')}" to activate`], { timeout: 3000, stdio: 'pipe' });
618
+ }
619
+ catch { /* ignore */ }
620
+ }
621
+ // ── Linux ──
622
+ function activateLinux(target) {
623
+ // Best-effort via wmctrl. No previous-window restoration.
624
+ try {
625
+ childProcess.execFileSync('wmctrl', ['-a', target.name], { timeout: 3000, stdio: 'pipe' });
626
+ }
627
+ catch { /* ignore */ }
628
+ return '';
629
+ }