@ashx-j/lunr 0.2.24 → 0.2.26

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 (254) hide show
  1. package/CHANGELOG.md +24 -1
  2. package/dist/builtin-extensions/index.d.ts.map +1 -1
  3. package/dist/builtin-extensions/index.js +1 -0
  4. package/dist/builtin-extensions/index.js.map +1 -1
  5. package/dist/builtin-extensions/lunr-computer-use.d.ts +3 -0
  6. package/dist/builtin-extensions/lunr-computer-use.d.ts.map +1 -0
  7. package/dist/builtin-extensions/lunr-computer-use.js +179 -0
  8. package/dist/builtin-extensions/lunr-computer-use.js.map +1 -0
  9. package/dist/builtin-extensions/pi-subagents/src/extension/schemas.d.ts.map +1 -1
  10. package/dist/builtin-extensions/pi-subagents/src/extension/schemas.js +1 -1
  11. package/dist/builtin-extensions/pi-subagents/src/extension/schemas.js.map +1 -1
  12. package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.d.ts +4 -4
  13. package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.d.ts.map +1 -1
  14. package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.js +8 -5
  15. package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.js.map +1 -1
  16. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.d.ts +1 -0
  17. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.d.ts.map +1 -1
  18. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js +11 -2
  19. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js.map +1 -1
  20. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.d.ts.map +1 -1
  21. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.js +3 -3
  22. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.js.map +1 -1
  23. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.d.ts.map +1 -1
  24. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js +15 -1
  25. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js.map +1 -1
  26. package/dist/builtin-extensions/pi-subagents/src/runs/shared/chain-outputs.d.ts +1 -0
  27. package/dist/builtin-extensions/pi-subagents/src/runs/shared/chain-outputs.d.ts.map +1 -1
  28. package/dist/builtin-extensions/pi-subagents/src/runs/shared/chain-outputs.js +5 -0
  29. package/dist/builtin-extensions/pi-subagents/src/runs/shared/chain-outputs.js.map +1 -1
  30. package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.d.ts +1 -1
  31. package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.d.ts.map +1 -1
  32. package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.js +2 -0
  33. package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.js.map +1 -1
  34. package/dist/builtin-extensions/pi-subagents/src/tui/communication.d.ts.map +1 -1
  35. package/dist/builtin-extensions/pi-subagents/src/tui/communication.js +1 -1
  36. package/dist/builtin-extensions/pi-subagents/src/tui/communication.js.map +1 -1
  37. package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts +1 -0
  38. package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts.map +1 -1
  39. package/dist/builtin-extensions/pi-subagents/src/tui/render.js +5 -3
  40. package/dist/builtin-extensions/pi-subagents/src/tui/render.js.map +1 -1
  41. package/dist/core/computer-use/adapter.d.ts +28 -0
  42. package/dist/core/computer-use/adapter.d.ts.map +1 -0
  43. package/dist/core/computer-use/adapter.js +133 -0
  44. package/dist/core/computer-use/adapter.js.map +1 -0
  45. package/dist/core/computer-use/image.d.ts +27 -0
  46. package/dist/core/computer-use/image.d.ts.map +1 -0
  47. package/dist/core/computer-use/image.js +72 -0
  48. package/dist/core/computer-use/image.js.map +1 -0
  49. package/dist/core/computer-use/lease.d.ts +18 -0
  50. package/dist/core/computer-use/lease.d.ts.map +1 -0
  51. package/dist/core/computer-use/lease.js +129 -0
  52. package/dist/core/computer-use/lease.js.map +1 -0
  53. package/dist/core/computer-use/macos-runtime.d.ts +14 -0
  54. package/dist/core/computer-use/macos-runtime.d.ts.map +1 -0
  55. package/dist/core/computer-use/macos-runtime.js +148 -0
  56. package/dist/core/computer-use/macos-runtime.js.map +1 -0
  57. package/dist/core/computer-use/policy.d.ts +19 -0
  58. package/dist/core/computer-use/policy.d.ts.map +1 -0
  59. package/dist/core/computer-use/policy.js +67 -0
  60. package/dist/core/computer-use/policy.js.map +1 -0
  61. package/dist/core/computer-use/release.generated.d.ts +31 -0
  62. package/dist/core/computer-use/release.generated.d.ts.map +1 -0
  63. package/dist/core/computer-use/release.generated.js +36 -0
  64. package/dist/core/computer-use/release.generated.js.map +1 -0
  65. package/dist/core/computer-use/runtime.d.ts +13 -0
  66. package/dist/core/computer-use/runtime.d.ts.map +1 -0
  67. package/dist/core/computer-use/runtime.js +158 -0
  68. package/dist/core/computer-use/runtime.js.map +1 -0
  69. package/dist/core/computer-use/schemas.d.ts +100 -0
  70. package/dist/core/computer-use/schemas.d.ts.map +1 -0
  71. package/dist/core/computer-use/schemas.js +79 -0
  72. package/dist/core/computer-use/schemas.js.map +1 -0
  73. package/dist/core/computer-use/windows-desktop.d.ts +3 -0
  74. package/dist/core/computer-use/windows-desktop.d.ts.map +1 -0
  75. package/dist/core/computer-use/windows-desktop.js +48 -0
  76. package/dist/core/computer-use/windows-desktop.js.map +1 -0
  77. package/dist/core/computer-use/workflow.d.ts +38 -0
  78. package/dist/core/computer-use/workflow.d.ts.map +1 -0
  79. package/dist/core/computer-use/workflow.js +560 -0
  80. package/dist/core/computer-use/workflow.js.map +1 -0
  81. package/dist/core/extensions/loader.d.ts.map +1 -1
  82. package/dist/core/extensions/loader.js +4 -0
  83. package/dist/core/extensions/loader.js.map +1 -1
  84. package/dist/core/permissions.d.ts +1 -1
  85. package/dist/core/permissions.d.ts.map +1 -1
  86. package/dist/core/permissions.js +14 -3
  87. package/dist/core/permissions.js.map +1 -1
  88. package/dist/core/plan-mode.d.ts.map +1 -1
  89. package/dist/core/plan-mode.js +9 -0
  90. package/dist/core/plan-mode.js.map +1 -1
  91. package/dist/core/settings-manager.d.ts +6 -0
  92. package/dist/core/settings-manager.d.ts.map +1 -1
  93. package/dist/core/settings-manager.js +19 -0
  94. package/dist/core/settings-manager.js.map +1 -1
  95. package/dist/core/subagent-event-transport.d.ts +3 -0
  96. package/dist/core/subagent-event-transport.d.ts.map +1 -0
  97. package/dist/core/subagent-event-transport.js +61 -0
  98. package/dist/core/subagent-event-transport.js.map +1 -0
  99. package/dist/gateway/adapters/discord.d.ts.map +1 -1
  100. package/dist/gateway/adapters/discord.js +4 -9
  101. package/dist/gateway/adapters/discord.js.map +1 -1
  102. package/dist/gateway/adapters/telegram.d.ts.map +1 -1
  103. package/dist/gateway/adapters/telegram.js +7 -0
  104. package/dist/gateway/adapters/telegram.js.map +1 -1
  105. package/dist/gateway/agent-bridge.d.ts +4 -1
  106. package/dist/gateway/agent-bridge.d.ts.map +1 -1
  107. package/dist/gateway/agent-bridge.js +57 -17
  108. package/dist/gateway/agent-bridge.js.map +1 -1
  109. package/dist/gateway/approval.d.ts.map +1 -1
  110. package/dist/gateway/approval.js +3 -3
  111. package/dist/gateway/approval.js.map +1 -1
  112. package/dist/gateway/authz.d.ts +4 -4
  113. package/dist/gateway/authz.d.ts.map +1 -1
  114. package/dist/gateway/authz.js +8 -12
  115. package/dist/gateway/authz.js.map +1 -1
  116. package/dist/gateway/buttons.d.ts.map +1 -1
  117. package/dist/gateway/buttons.js +29 -19
  118. package/dist/gateway/buttons.js.map +1 -1
  119. package/dist/gateway/commands.d.ts +2 -0
  120. package/dist/gateway/commands.d.ts.map +1 -1
  121. package/dist/gateway/commands.js +35 -18
  122. package/dist/gateway/commands.js.map +1 -1
  123. package/dist/gateway/config.d.ts +1 -0
  124. package/dist/gateway/config.d.ts.map +1 -1
  125. package/dist/gateway/config.js +2 -0
  126. package/dist/gateway/config.js.map +1 -1
  127. package/dist/gateway/cron.d.ts +1 -1
  128. package/dist/gateway/cron.d.ts.map +1 -1
  129. package/dist/gateway/cron.js +22 -8
  130. package/dist/gateway/cron.js.map +1 -1
  131. package/dist/gateway/index.d.ts.map +1 -1
  132. package/dist/gateway/index.js +26 -26
  133. package/dist/gateway/index.js.map +1 -1
  134. package/dist/gateway/mobile-commands.d.ts.map +1 -1
  135. package/dist/gateway/mobile-commands.js +11 -11
  136. package/dist/gateway/mobile-commands.js.map +1 -1
  137. package/dist/gateway/presenter.d.ts +12 -1
  138. package/dist/gateway/presenter.d.ts.map +1 -1
  139. package/dist/gateway/presenter.js +148 -50
  140. package/dist/gateway/presenter.js.map +1 -1
  141. package/dist/gateway/router.d.ts +5 -5
  142. package/dist/gateway/router.d.ts.map +1 -1
  143. package/dist/gateway/router.js +95 -43
  144. package/dist/gateway/router.js.map +1 -1
  145. package/dist/gateway/service.d.ts.map +1 -1
  146. package/dist/gateway/service.js +13 -4
  147. package/dist/gateway/service.js.map +1 -1
  148. package/dist/gateway/setup.d.ts +5 -0
  149. package/dist/gateway/setup.d.ts.map +1 -1
  150. package/dist/gateway/setup.js +101 -43
  151. package/dist/gateway/setup.js.map +1 -1
  152. package/dist/gateway/stream.d.ts +6 -5
  153. package/dist/gateway/stream.d.ts.map +1 -1
  154. package/dist/gateway/stream.js +24 -11
  155. package/dist/gateway/stream.js.map +1 -1
  156. package/dist/modes/interactive/components/settings-selector.d.ts +4 -0
  157. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  158. package/dist/modes/interactive/components/settings-selector.js +20 -0
  159. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  160. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  161. package/dist/modes/interactive/interactive-mode.js +8 -0
  162. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  163. package/dist/modes/print-mode.d.ts.map +1 -1
  164. package/dist/modes/print-mode.js +9 -1
  165. package/dist/modes/print-mode.js.map +1 -1
  166. package/dist/node-runtime/adapter-VFG7WNPX.js +17 -0
  167. package/dist/node-runtime/{agent-session-services-IEF7LQWD.js → agent-session-services-5YXS2PLF.js} +13 -10
  168. package/dist/node-runtime/{builtin-extensions-EBAWTH4M.js → builtin-extensions-I2HIFEMY.js} +3 -2
  169. package/dist/node-runtime/{chunk-K5AGHH57.js → chunk-2CFDTH5B.js} +7 -3
  170. package/dist/node-runtime/{chunk-VWCE2HSZ.js → chunk-2HMIRK7W.js} +4 -4
  171. package/dist/node-runtime/chunk-2IDTZAG5.js +1415 -0
  172. package/dist/node-runtime/{chunk-IGV54Q5V.js → chunk-3MISGG4S.js} +137 -76
  173. package/dist/node-runtime/chunk-4SBQAI4T.js +2185 -0
  174. package/dist/node-runtime/{chunk-WHLRAGUQ.js → chunk-5B5QN3ZQ.js} +16 -16
  175. package/dist/node-runtime/chunk-5B6VKFEV.js +180 -0
  176. package/dist/node-runtime/{chunk-AD6VXAO7.js → chunk-5Q4A37RB.js} +15 -104
  177. package/dist/node-runtime/{chunk-4TLO4PO2.js → chunk-7IQGBKBJ.js} +7 -1401
  178. package/dist/node-runtime/{chunk-R3K2F5GI.js → chunk-B4HP6ZWM.js} +2 -0
  179. package/dist/node-runtime/{chunk-OCVIXVTZ.js → chunk-D5UCKPBQ.js} +12 -1
  180. package/dist/node-runtime/chunk-DVQSHCVP.js +97 -0
  181. package/dist/node-runtime/{chunk-HFVZUPFJ.js → chunk-E75WFZ33.js} +2 -2
  182. package/dist/node-runtime/chunk-FY4A63RK.js +73 -0
  183. package/dist/node-runtime/{chunk-RORY2HMJ.js → chunk-I74LN5JG.js} +16 -1
  184. package/dist/node-runtime/chunk-IKU6Y7DL.js +287 -0
  185. package/dist/node-runtime/{chunk-QM43FEAE.js → chunk-L24TPBS4.js} +6 -5
  186. package/dist/node-runtime/{chunk-DE2JB6J5.js → chunk-LJTIVM7I.js} +7 -7
  187. package/dist/node-runtime/{chunk-DSIKTUPW.js → chunk-LWJXTA6Z.js} +274 -2433
  188. package/dist/node-runtime/{chunk-YVI6L6LU.js → chunk-P7XBVXGT.js} +36 -21
  189. package/dist/node-runtime/{chunk-OVX6X377.js → chunk-PTFBPO3C.js} +1 -1
  190. package/dist/node-runtime/{chunk-F4FLTQKV.js → chunk-RAK2QA2B.js} +186 -1529
  191. package/dist/node-runtime/{chunk-L3LX4SNR.js → chunk-RCR3XAQY.js} +36 -8
  192. package/dist/node-runtime/chunk-RGQAEOM5.js +81 -0
  193. package/dist/node-runtime/{chunk-UWPJL22I.js → chunk-SLVOAQOY.js} +15 -4
  194. package/dist/node-runtime/chunk-SN2KSMPQ.js +1364 -0
  195. package/dist/node-runtime/{chunk-FU6OODRZ.js → chunk-SPVDBUOS.js} +1 -1
  196. package/dist/node-runtime/{chunk-5Q3EHOHI.js → chunk-T4DA4XE7.js} +19 -17
  197. package/dist/node-runtime/chunk-U5F4IC7R.js +53 -0
  198. package/dist/node-runtime/{chunk-UP2XBVH5.js → chunk-UOEDI7RP.js} +1 -1
  199. package/dist/node-runtime/{chunk-Y73WPE6S.js → chunk-UVWCDQYF.js} +79 -44
  200. package/dist/node-runtime/{chunk-ZXSGTGJ6.js → chunk-WIF24I7G.js} +21 -5
  201. package/dist/node-runtime/{chunk-OF7PWMG4.js → chunk-X3PGBLQ7.js} +3 -87
  202. package/dist/node-runtime/chunk-XHIRAZ26.js +108 -0
  203. package/dist/node-runtime/{chunk-YDO2F2IA.js → chunk-YWOJIGFY.js} +1 -1
  204. package/dist/node-runtime/{command-7BG7VVTS.js → command-FSBU2EVZ.js} +5 -5
  205. package/dist/node-runtime/{commands-NZLSOHPE.js → commands-EMBQQVVT.js} +4 -2
  206. package/dist/node-runtime/{commands-QFDKNQTL.js → commands-NAAL7KNT.js} +7 -6
  207. package/dist/node-runtime/{config-RORQUQFG.js → config-D4QUPAHX.js} +1 -1
  208. package/dist/node-runtime/{direct-tool-executor-77GW4F5P.js → direct-tool-executor-4D7UXYU4.js} +7 -4
  209. package/dist/node-runtime/{gateway-TWR3N65G.js → gateway-DQM333YV.js} +140 -85
  210. package/dist/node-runtime/index.js +28 -21
  211. package/dist/node-runtime/{init-HS6NQXSK.js → init-P5AUV77I.js} +4 -2
  212. package/dist/node-runtime/{install-cli-VAP6KBFN.js → install-cli-NN4YAU44.js} +3 -3
  213. package/dist/node-runtime/{interactive-mode-6J5VZ2TT.js → interactive-mode-YOHZVMKX.js} +14 -11
  214. package/dist/node-runtime/{lunr-browser-J5ZZYVGM.js → lunr-browser-IR7TL3J7.js} +3 -3
  215. package/dist/node-runtime/lunr-computer-use-Y23CCDIJ.js +158 -0
  216. package/dist/node-runtime/{lunr-cron-CXOL37AL.js → lunr-cron-USHC4LXH.js} +9 -7
  217. package/dist/node-runtime/main.js +19 -15
  218. package/dist/node-runtime/{mcp-auth-flow-QIXHW6QN.js → mcp-auth-flow-QVLFVLEO.js} +2 -1
  219. package/dist/node-runtime/{mobile-commands-VTBM5DSZ.js → mobile-commands-O5LCHL32.js} +6 -5
  220. package/dist/node-runtime/{package-manager-cli-ZLW5DZXF.js → package-manager-cli-Q7BL6KZO.js} +12 -8
  221. package/dist/node-runtime/{pi-mcp-adapter-5UKBZP44.js → pi-mcp-adapter-3PHF4KZ4.js} +5 -5
  222. package/dist/node-runtime/{pi-subagents-XPCLLKIM.js → pi-subagents-7IBSSGEW.js} +27 -21
  223. package/dist/node-runtime/{print-mode-XSFM26EL.js → print-mode-XQ76CYMT.js} +2 -1
  224. package/dist/node-runtime/{proxy-modes-LGEUYD7R.js → proxy-modes-5FAPSZEZ.js} +7 -4
  225. package/dist/node-runtime/rpc-entry.js +19 -15
  226. package/dist/node-runtime/runtime-EFPPD2UW.js +21 -0
  227. package/dist/node-runtime/{runtime-bridges-QYXUX2TG.js → runtime-bridges-7WVCLI76.js} +6 -5
  228. package/dist/node-runtime/{service-ISSP6VHE.js → service-MDQIPQ26.js} +1 -1
  229. package/dist/node-runtime/{settings-manager-WCQDUVQB.js → settings-manager-DJDM5AHM.js} +5 -4
  230. package/dist/node-runtime/setup-PFBWRNUI.js +215 -0
  231. package/dist/node-runtime/{subagent-executor-OTNISDQU.js → subagent-executor-LPZ4BHWE.js} +32 -14
  232. package/dist/node-runtime/{update-cli-VBR2777K.js → update-cli-HNMOTNGX.js} +5 -4
  233. package/dist/node-runtime/workflow-OHPBEFO4.js +637 -0
  234. package/dist/utils/image-resize-core.d.ts +2 -0
  235. package/dist/utils/image-resize-core.d.ts.map +1 -1
  236. package/dist/utils/image-resize-core.js +10 -0
  237. package/dist/utils/image-resize-core.js.map +1 -1
  238. package/docs/computer-use.md +362 -0
  239. package/docs/features.md +9 -7
  240. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  241. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  242. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  243. package/examples/extensions/gondolin/package-lock.json +2 -2
  244. package/examples/extensions/gondolin/package.json +1 -1
  245. package/examples/extensions/sandbox/package-lock.json +2 -2
  246. package/examples/extensions/sandbox/package.json +1 -1
  247. package/examples/extensions/with-deps/package-lock.json +2 -2
  248. package/examples/extensions/with-deps/package.json +1 -1
  249. package/install-lock/package-lock.json +3841 -0
  250. package/install-lock/package.json +18 -0
  251. package/native/computer-use/LICENSE.md +21 -0
  252. package/npm-shrinkwrap.json +3822 -0
  253. package/package.json +15 -9
  254. package/dist/node-runtime/setup-YRBKH2LD.js +0 -155
@@ -3,6 +3,7 @@ export interface ImageResizeOptions {
3
3
  maxHeight?: number;
4
4
  maxBytes?: number;
5
5
  jpegQuality?: number;
6
+ includePixelFingerprint?: boolean;
6
7
  }
7
8
  export interface ResizedImage {
8
9
  data: string;
@@ -12,6 +13,7 @@ export interface ResizedImage {
12
13
  width: number;
13
14
  height: number;
14
15
  wasResized: boolean;
16
+ fingerprint?: string;
15
17
  }
16
18
  /**
17
19
  * Resize an image to fit within the specified max dimensions and encoded file size.
@@ -1 +1 @@
1
- {"version":3,"file":"image-resize-core.d.ts","sourceRoot":"","sources":["../../src/utils/image-resize-core.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;CACpB;AA2BD;;;;;;;;;;;;GAYG;AACH,wBAAsB,oBAAoB,CACzC,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAqG9B","sourcesContent":["import { applyExifOrientation } from \"./exif-orientation.ts\";\nimport { loadPhoton } from \"./photon.ts\";\n\nexport interface ImageResizeOptions {\n\tmaxWidth?: number; // Default: 2000\n\tmaxHeight?: number; // Default: 2000\n\tmaxBytes?: number; // Default: 4.5MB of base64 payload (below Anthropic's 5MB limit)\n\tjpegQuality?: number; // Default: 80\n}\n\nexport interface ResizedImage {\n\tdata: string; // base64\n\tmimeType: string;\n\toriginalWidth: number;\n\toriginalHeight: number;\n\twidth: number;\n\theight: number;\n\twasResized: boolean;\n}\n\n// 4.5MB of base64 payload. Provides headroom below Anthropic's 5MB limit.\nconst DEFAULT_MAX_BYTES = 4.5 * 1024 * 1024;\n\nconst DEFAULT_OPTIONS: Required<ImageResizeOptions> = {\n\tmaxWidth: 2000,\n\tmaxHeight: 2000,\n\tmaxBytes: DEFAULT_MAX_BYTES,\n\tjpegQuality: 80,\n};\n\ninterface EncodedCandidate {\n\tdata: string;\n\tencodedSize: number;\n\tmimeType: string;\n}\n\nfunction encodeCandidate(buffer: Uint8Array, mimeType: string): EncodedCandidate {\n\tconst data = Buffer.from(buffer).toString(\"base64\");\n\treturn {\n\t\tdata,\n\t\tencodedSize: Buffer.byteLength(data, \"utf-8\"),\n\t\tmimeType,\n\t};\n}\n\n/**\n * Resize an image to fit within the specified max dimensions and encoded file size.\n * Returns null if the image cannot be resized below maxBytes.\n *\n * Uses Photon (Rust/WASM) for image processing. If Photon is not available,\n * returns null.\n *\n * Strategy for staying under maxBytes:\n * 1. First resize to maxWidth/maxHeight\n * 2. Try both PNG and JPEG formats, pick the smaller one\n * 3. If still too large, try JPEG with decreasing quality\n * 4. If still too large, progressively reduce dimensions until 1x1\n */\nexport async function resizeImageInProcess(\n\tinputBytes: Uint8Array,\n\tmimeType: string,\n\toptions?: ImageResizeOptions,\n): Promise<ResizedImage | null> {\n\tconst opts = { ...DEFAULT_OPTIONS, ...options };\n\tconst inputBase64Size = Math.ceil(inputBytes.byteLength / 3) * 4;\n\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\treturn null;\n\t}\n\n\tlet image: ReturnType<typeof photon.PhotonImage.new_from_byteslice> | undefined;\n\ttry {\n\t\tconst rawImage = photon.PhotonImage.new_from_byteslice(inputBytes);\n\t\timage = applyExifOrientation(photon, rawImage, inputBytes);\n\t\tif (image !== rawImage) rawImage.free();\n\n\t\tconst originalWidth = image.get_width();\n\t\tconst originalHeight = image.get_height();\n\t\tconst format = mimeType.split(\"/\")[1] ?? \"png\";\n\n\t\t// Check if already within all limits (dimensions AND encoded size)\n\t\tif (originalWidth <= opts.maxWidth && originalHeight <= opts.maxHeight && inputBase64Size < opts.maxBytes) {\n\t\t\treturn {\n\t\t\t\tdata: Buffer.from(inputBytes).toString(\"base64\"),\n\t\t\t\tmimeType: mimeType || `image/${format}`,\n\t\t\t\toriginalWidth,\n\t\t\t\toriginalHeight,\n\t\t\t\twidth: originalWidth,\n\t\t\t\theight: originalHeight,\n\t\t\t\twasResized: false,\n\t\t\t};\n\t\t}\n\n\t\t// Calculate initial dimensions respecting max limits\n\t\tlet targetWidth = originalWidth;\n\t\tlet targetHeight = originalHeight;\n\n\t\tif (targetWidth > opts.maxWidth) {\n\t\t\ttargetHeight = Math.round((targetHeight * opts.maxWidth) / targetWidth);\n\t\t\ttargetWidth = opts.maxWidth;\n\t\t}\n\t\tif (targetHeight > opts.maxHeight) {\n\t\t\ttargetWidth = Math.round((targetWidth * opts.maxHeight) / targetHeight);\n\t\t\ttargetHeight = opts.maxHeight;\n\t\t}\n\n\t\tfunction tryEncodings(width: number, height: number, jpegQualities: number[]): EncodedCandidate[] {\n\t\t\tconst resized = photon!.resize(image!, width, height, photon!.SamplingFilter.Lanczos3);\n\n\t\t\ttry {\n\t\t\t\tconst candidates: EncodedCandidate[] = [encodeCandidate(resized.get_bytes(), \"image/png\")];\n\t\t\t\tfor (const quality of jpegQualities) {\n\t\t\t\t\tcandidates.push(encodeCandidate(resized.get_bytes_jpeg(quality), \"image/jpeg\"));\n\t\t\t\t}\n\t\t\t\treturn candidates;\n\t\t\t} finally {\n\t\t\t\tresized.free();\n\t\t\t}\n\t\t}\n\n\t\tconst qualitySteps = Array.from(new Set([opts.jpegQuality, 85, 70, 55, 40]));\n\t\tlet currentWidth = targetWidth;\n\t\tlet currentHeight = targetHeight;\n\n\t\twhile (true) {\n\t\t\tconst candidates = tryEncodings(currentWidth, currentHeight, qualitySteps);\n\t\t\tfor (const candidate of candidates) {\n\t\t\t\tif (candidate.encodedSize < opts.maxBytes) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata: candidate.data,\n\t\t\t\t\t\tmimeType: candidate.mimeType,\n\t\t\t\t\t\toriginalWidth,\n\t\t\t\t\t\toriginalHeight,\n\t\t\t\t\t\twidth: currentWidth,\n\t\t\t\t\t\theight: currentHeight,\n\t\t\t\t\t\twasResized: true,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentWidth === 1 && currentHeight === 1) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst nextWidth = currentWidth === 1 ? 1 : Math.max(1, Math.floor(currentWidth * 0.75));\n\t\t\tconst nextHeight = currentHeight === 1 ? 1 : Math.max(1, Math.floor(currentHeight * 0.75));\n\t\t\tif (nextWidth === currentWidth && nextHeight === currentHeight) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcurrentWidth = nextWidth;\n\t\t\tcurrentHeight = nextHeight;\n\t\t}\n\n\t\treturn null;\n\t} catch {\n\t\treturn null;\n\t} finally {\n\t\tif (image) {\n\t\t\timage.free();\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"image-resize-core.d.ts","sourceRoot":"","sources":["../../src/utils/image-resize-core.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uBAAuB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AA4BD;;;;;;;;;;;;GAYG;AACH,wBAAsB,oBAAoB,CACzC,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CA6G9B","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { applyExifOrientation } from \"./exif-orientation.ts\";\nimport { loadPhoton } from \"./photon.ts\";\n\nexport interface ImageResizeOptions {\n\tmaxWidth?: number; // Default: 2000\n\tmaxHeight?: number; // Default: 2000\n\tmaxBytes?: number; // Default: 4.5MB of base64 payload (below Anthropic's 5MB limit)\n\tjpegQuality?: number; // Default: 80\n\tincludePixelFingerprint?: boolean;\n}\n\nexport interface ResizedImage {\n\tdata: string; // base64\n\tmimeType: string;\n\toriginalWidth: number;\n\toriginalHeight: number;\n\twidth: number;\n\theight: number;\n\twasResized: boolean;\n\tfingerprint?: string;\n}\n\n// 4.5MB of base64 payload. Provides headroom below Anthropic's 5MB limit.\nconst DEFAULT_MAX_BYTES = 4.5 * 1024 * 1024;\n\nconst DEFAULT_OPTIONS: Required<ImageResizeOptions> = {\n\tmaxWidth: 2000,\n\tmaxHeight: 2000,\n\tmaxBytes: DEFAULT_MAX_BYTES,\n\tjpegQuality: 80,\n\tincludePixelFingerprint: false,\n};\n\ninterface EncodedCandidate {\n\tdata: string;\n\tencodedSize: number;\n\tmimeType: string;\n}\n\nfunction encodeCandidate(buffer: Uint8Array, mimeType: string): EncodedCandidate {\n\tconst data = Buffer.from(buffer).toString(\"base64\");\n\treturn {\n\t\tdata,\n\t\tencodedSize: Buffer.byteLength(data, \"utf-8\"),\n\t\tmimeType,\n\t};\n}\n\n/**\n * Resize an image to fit within the specified max dimensions and encoded file size.\n * Returns null if the image cannot be resized below maxBytes.\n *\n * Uses Photon (Rust/WASM) for image processing. If Photon is not available,\n * returns null.\n *\n * Strategy for staying under maxBytes:\n * 1. First resize to maxWidth/maxHeight\n * 2. Try both PNG and JPEG formats, pick the smaller one\n * 3. If still too large, try JPEG with decreasing quality\n * 4. If still too large, progressively reduce dimensions until 1x1\n */\nexport async function resizeImageInProcess(\n\tinputBytes: Uint8Array,\n\tmimeType: string,\n\toptions?: ImageResizeOptions,\n): Promise<ResizedImage | null> {\n\tconst opts = { ...DEFAULT_OPTIONS, ...options };\n\tconst inputBase64Size = Math.ceil(inputBytes.byteLength / 3) * 4;\n\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\treturn null;\n\t}\n\n\tlet image: ReturnType<typeof photon.PhotonImage.new_from_byteslice> | undefined;\n\ttry {\n\t\tconst rawImage = photon.PhotonImage.new_from_byteslice(inputBytes);\n\t\timage = applyExifOrientation(photon, rawImage, inputBytes);\n\t\tif (image !== rawImage) rawImage.free();\n\n\t\tconst originalWidth = image.get_width();\n\t\tconst originalHeight = image.get_height();\n\t\tconst format = mimeType.split(\"/\")[1] ?? \"png\";\n\t\tconst fingerprint = opts.includePixelFingerprint\n\t\t\t? createHash(\"sha256\")\n\t\t\t\t\t.update(`${originalWidth}x${originalHeight}:`)\n\t\t\t\t\t.update(image.get_raw_pixels())\n\t\t\t\t\t.digest(\"hex\")\n\t\t\t: undefined;\n\n\t\t// Check if already within all limits (dimensions AND encoded size)\n\t\tif (originalWidth <= opts.maxWidth && originalHeight <= opts.maxHeight && inputBase64Size < opts.maxBytes) {\n\t\t\treturn {\n\t\t\t\tdata: Buffer.from(inputBytes).toString(\"base64\"),\n\t\t\t\tmimeType: mimeType || `image/${format}`,\n\t\t\t\toriginalWidth,\n\t\t\t\toriginalHeight,\n\t\t\t\twidth: originalWidth,\n\t\t\t\theight: originalHeight,\n\t\t\t\twasResized: false,\n\t\t\t\t...(fingerprint ? { fingerprint } : {}),\n\t\t\t};\n\t\t}\n\n\t\t// Calculate initial dimensions respecting max limits\n\t\tlet targetWidth = originalWidth;\n\t\tlet targetHeight = originalHeight;\n\n\t\tif (targetWidth > opts.maxWidth) {\n\t\t\ttargetHeight = Math.round((targetHeight * opts.maxWidth) / targetWidth);\n\t\t\ttargetWidth = opts.maxWidth;\n\t\t}\n\t\tif (targetHeight > opts.maxHeight) {\n\t\t\ttargetWidth = Math.round((targetWidth * opts.maxHeight) / targetHeight);\n\t\t\ttargetHeight = opts.maxHeight;\n\t\t}\n\n\t\tfunction tryEncodings(width: number, height: number, jpegQualities: number[]): EncodedCandidate[] {\n\t\t\tconst resized = photon!.resize(image!, width, height, photon!.SamplingFilter.Lanczos3);\n\n\t\t\ttry {\n\t\t\t\tconst candidates: EncodedCandidate[] = [encodeCandidate(resized.get_bytes(), \"image/png\")];\n\t\t\t\tfor (const quality of jpegQualities) {\n\t\t\t\t\tcandidates.push(encodeCandidate(resized.get_bytes_jpeg(quality), \"image/jpeg\"));\n\t\t\t\t}\n\t\t\t\treturn candidates;\n\t\t\t} finally {\n\t\t\t\tresized.free();\n\t\t\t}\n\t\t}\n\n\t\tconst qualitySteps = Array.from(new Set([opts.jpegQuality, 85, 70, 55, 40]));\n\t\tlet currentWidth = targetWidth;\n\t\tlet currentHeight = targetHeight;\n\n\t\twhile (true) {\n\t\t\tconst candidates = tryEncodings(currentWidth, currentHeight, qualitySteps);\n\t\t\tfor (const candidate of candidates) {\n\t\t\t\tif (candidate.encodedSize < opts.maxBytes) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata: candidate.data,\n\t\t\t\t\t\tmimeType: candidate.mimeType,\n\t\t\t\t\t\toriginalWidth,\n\t\t\t\t\t\toriginalHeight,\n\t\t\t\t\t\twidth: currentWidth,\n\t\t\t\t\t\theight: currentHeight,\n\t\t\t\t\t\twasResized: true,\n\t\t\t\t\t\t...(fingerprint ? { fingerprint } : {}),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentWidth === 1 && currentHeight === 1) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst nextWidth = currentWidth === 1 ? 1 : Math.max(1, Math.floor(currentWidth * 0.75));\n\t\t\tconst nextHeight = currentHeight === 1 ? 1 : Math.max(1, Math.floor(currentHeight * 0.75));\n\t\t\tif (nextWidth === currentWidth && nextHeight === currentHeight) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcurrentWidth = nextWidth;\n\t\t\tcurrentHeight = nextHeight;\n\t\t}\n\n\t\treturn null;\n\t} catch {\n\t\treturn null;\n\t} finally {\n\t\tif (image) {\n\t\t\timage.free();\n\t\t}\n\t}\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { createHash } from "node:crypto";
1
2
  import { applyExifOrientation } from "./exif-orientation.js";
2
3
  import { loadPhoton } from "./photon.js";
3
4
  // 4.5MB of base64 payload. Provides headroom below Anthropic's 5MB limit.
@@ -7,6 +8,7 @@ const DEFAULT_OPTIONS = {
7
8
  maxHeight: 2000,
8
9
  maxBytes: DEFAULT_MAX_BYTES,
9
10
  jpegQuality: 80,
11
+ includePixelFingerprint: false,
10
12
  };
11
13
  function encodeCandidate(buffer, mimeType) {
12
14
  const data = Buffer.from(buffer).toString("base64");
@@ -45,6 +47,12 @@ export async function resizeImageInProcess(inputBytes, mimeType, options) {
45
47
  const originalWidth = image.get_width();
46
48
  const originalHeight = image.get_height();
47
49
  const format = mimeType.split("/")[1] ?? "png";
50
+ const fingerprint = opts.includePixelFingerprint
51
+ ? createHash("sha256")
52
+ .update(`${originalWidth}x${originalHeight}:`)
53
+ .update(image.get_raw_pixels())
54
+ .digest("hex")
55
+ : undefined;
48
56
  // Check if already within all limits (dimensions AND encoded size)
49
57
  if (originalWidth <= opts.maxWidth && originalHeight <= opts.maxHeight && inputBase64Size < opts.maxBytes) {
50
58
  return {
@@ -55,6 +63,7 @@ export async function resizeImageInProcess(inputBytes, mimeType, options) {
55
63
  width: originalWidth,
56
64
  height: originalHeight,
57
65
  wasResized: false,
66
+ ...(fingerprint ? { fingerprint } : {}),
58
67
  };
59
68
  }
60
69
  // Calculate initial dimensions respecting max limits
@@ -96,6 +105,7 @@ export async function resizeImageInProcess(inputBytes, mimeType, options) {
96
105
  width: currentWidth,
97
106
  height: currentHeight,
98
107
  wasResized: true,
108
+ ...(fingerprint ? { fingerprint } : {}),
99
109
  };
100
110
  }
101
111
  }
@@ -1 +1 @@
1
- {"version":3,"file":"image-resize-core.js","sourceRoot":"","sources":["../../src/utils/image-resize-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,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AM;YACP,CAAC;YAED,MAAM,SAAS,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC;YACxF,MAAM,UAAU,GAAG,aAAa,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC,CAAC;YAC3F,IAAI,SAAS,KAAK,YAAY,IAAI,UAAU,KAAK,aAAa,EAAE,CAAC;gBAChE,MAAM;YACP,CAAC;YAED,YAAY,GAAG,SAAS,CAAC;YACzB,aAAa,GAAG,UAAU,CAAC;QAC5B,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;YAAS,CAAC;QACV,IAAI,KAAK,EAAE,CAAC;YACX,KAAK,CAAC,IAAI,EAAE,CAAC;QACd,CAAC;IACF,CAAC;AAAA,CACD","sourcesContent":["import { applyExifOrientation } from \"./exif-orientation.ts\";\nimport { loadPhoton } from \"./photon.ts\";\n\nexport interface ImageResizeOptions {\n\tmaxWidth?: number; // Default: 2000\n\tmaxHeight?: number; // Default: 2000\n\tmaxBytes?: number; // Default: 4.5MB of base64 payload (below Anthropic's 5MB limit)\n\tjpegQuality?: number; // Default: 80\n}\n\nexport interface ResizedImage {\n\tdata: string; // base64\n\tmimeType: string;\n\toriginalWidth: number;\n\toriginalHeight: number;\n\twidth: number;\n\theight: number;\n\twasResized: boolean;\n}\n\n// 4.5MB of base64 payload. Provides headroom below Anthropic's 5MB limit.\nconst DEFAULT_MAX_BYTES = 4.5 * 1024 * 1024;\n\nconst DEFAULT_OPTIONS: Required<ImageResizeOptions> = {\n\tmaxWidth: 2000,\n\tmaxHeight: 2000,\n\tmaxBytes: DEFAULT_MAX_BYTES,\n\tjpegQuality: 80,\n};\n\ninterface EncodedCandidate {\n\tdata: string;\n\tencodedSize: number;\n\tmimeType: string;\n}\n\nfunction encodeCandidate(buffer: Uint8Array, mimeType: string): EncodedCandidate {\n\tconst data = Buffer.from(buffer).toString(\"base64\");\n\treturn {\n\t\tdata,\n\t\tencodedSize: Buffer.byteLength(data, \"utf-8\"),\n\t\tmimeType,\n\t};\n}\n\n/**\n * Resize an image to fit within the specified max dimensions and encoded file size.\n * Returns null if the image cannot be resized below maxBytes.\n *\n * Uses Photon (Rust/WASM) for image processing. If Photon is not available,\n * returns null.\n *\n * Strategy for staying under maxBytes:\n * 1. First resize to maxWidth/maxHeight\n * 2. Try both PNG and JPEG formats, pick the smaller one\n * 3. If still too large, try JPEG with decreasing quality\n * 4. If still too large, progressively reduce dimensions until 1x1\n */\nexport async function resizeImageInProcess(\n\tinputBytes: Uint8Array,\n\tmimeType: string,\n\toptions?: ImageResizeOptions,\n): Promise<ResizedImage | null> {\n\tconst opts = { ...DEFAULT_OPTIONS, ...options };\n\tconst inputBase64Size = Math.ceil(inputBytes.byteLength / 3) * 4;\n\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\treturn null;\n\t}\n\n\tlet image: ReturnType<typeof photon.PhotonImage.new_from_byteslice> | undefined;\n\ttry {\n\t\tconst rawImage = photon.PhotonImage.new_from_byteslice(inputBytes);\n\t\timage = applyExifOrientation(photon, rawImage, inputBytes);\n\t\tif (image !== rawImage) rawImage.free();\n\n\t\tconst originalWidth = image.get_width();\n\t\tconst originalHeight = image.get_height();\n\t\tconst format = mimeType.split(\"/\")[1] ?? \"png\";\n\n\t\t// Check if already within all limits (dimensions AND encoded size)\n\t\tif (originalWidth <= opts.maxWidth && originalHeight <= opts.maxHeight && inputBase64Size < opts.maxBytes) {\n\t\t\treturn {\n\t\t\t\tdata: Buffer.from(inputBytes).toString(\"base64\"),\n\t\t\t\tmimeType: mimeType || `image/${format}`,\n\t\t\t\toriginalWidth,\n\t\t\t\toriginalHeight,\n\t\t\t\twidth: originalWidth,\n\t\t\t\theight: originalHeight,\n\t\t\t\twasResized: false,\n\t\t\t};\n\t\t}\n\n\t\t// Calculate initial dimensions respecting max limits\n\t\tlet targetWidth = originalWidth;\n\t\tlet targetHeight = originalHeight;\n\n\t\tif (targetWidth > opts.maxWidth) {\n\t\t\ttargetHeight = Math.round((targetHeight * opts.maxWidth) / targetWidth);\n\t\t\ttargetWidth = opts.maxWidth;\n\t\t}\n\t\tif (targetHeight > opts.maxHeight) {\n\t\t\ttargetWidth = Math.round((targetWidth * opts.maxHeight) / targetHeight);\n\t\t\ttargetHeight = opts.maxHeight;\n\t\t}\n\n\t\tfunction tryEncodings(width: number, height: number, jpegQualities: number[]): EncodedCandidate[] {\n\t\t\tconst resized = photon!.resize(image!, width, height, photon!.SamplingFilter.Lanczos3);\n\n\t\t\ttry {\n\t\t\t\tconst candidates: EncodedCandidate[] = [encodeCandidate(resized.get_bytes(), \"image/png\")];\n\t\t\t\tfor (const quality of jpegQualities) {\n\t\t\t\t\tcandidates.push(encodeCandidate(resized.get_bytes_jpeg(quality), \"image/jpeg\"));\n\t\t\t\t}\n\t\t\t\treturn candidates;\n\t\t\t} finally {\n\t\t\t\tresized.free();\n\t\t\t}\n\t\t}\n\n\t\tconst qualitySteps = Array.from(new Set([opts.jpegQuality, 85, 70, 55, 40]));\n\t\tlet currentWidth = targetWidth;\n\t\tlet currentHeight = targetHeight;\n\n\t\twhile (true) {\n\t\t\tconst candidates = tryEncodings(currentWidth, currentHeight, qualitySteps);\n\t\t\tfor (const candidate of candidates) {\n\t\t\t\tif (candidate.encodedSize < opts.maxBytes) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata: candidate.data,\n\t\t\t\t\t\tmimeType: candidate.mimeType,\n\t\t\t\t\t\toriginalWidth,\n\t\t\t\t\t\toriginalHeight,\n\t\t\t\t\t\twidth: currentWidth,\n\t\t\t\t\t\theight: currentHeight,\n\t\t\t\t\t\twasResized: true,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentWidth === 1 && currentHeight === 1) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst nextWidth = currentWidth === 1 ? 1 : Math.max(1, Math.floor(currentWidth * 0.75));\n\t\t\tconst nextHeight = currentHeight === 1 ? 1 : Math.max(1, Math.floor(currentHeight * 0.75));\n\t\t\tif (nextWidth === currentWidth && nextHeight === currentHeight) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcurrentWidth = nextWidth;\n\t\t\tcurrentHeight = nextHeight;\n\t\t}\n\n\t\treturn null;\n\t} catch {\n\t\treturn null;\n\t} finally {\n\t\tif (image) {\n\t\t\timage.free();\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"image-resize-core.js","sourceRoot":"","sources":["../../src/utils/image-resize-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAqBzC,0EAA0E;AAC1E,MAAM,iBAAiB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAE5C,MAAM,eAAe,GAAiC;IACrD,QAAQ,EAAE,IAAI;IACd,SAAS,EAAE,IAAI;IACf,QAAQ,EAAE,iBAAiB;IAC3B,WAAW,EAAE,EAAE;IACf,uBAAuB,EAAE,KAAK;CAC9B,CAAC;AAQF,SAAS,eAAe,CAAC,MAAkB,EAAE,QAAgB,EAAoB;IAChF,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACpD,OAAO;QACN,IAAI;QACJ,WAAW,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC;QAC7C,QAAQ;KACR,C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CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC;YACxF,MAAM,UAAU,GAAG,aAAa,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC,CAAC;YAC3F,IAAI,SAAS,KAAK,YAAY,IAAI,UAAU,KAAK,aAAa,EAAE,CAAC;gBAChE,MAAM;YACP,CAAC;YAED,YAAY,GAAG,SAAS,CAAC;YACzB,aAAa,GAAG,UAAU,CAAC;QAC5B,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;YAAS,CAAC;QACV,IAAI,KAAK,EAAE,CAAC;YACX,KAAK,CAAC,IAAI,EAAE,CAAC;QACd,CAAC;IACF,CAAC;AAAA,CACD","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { applyExifOrientation } from \"./exif-orientation.ts\";\nimport { loadPhoton } from \"./photon.ts\";\n\nexport interface ImageResizeOptions {\n\tmaxWidth?: number; // Default: 2000\n\tmaxHeight?: number; // Default: 2000\n\tmaxBytes?: number; // Default: 4.5MB of base64 payload (below Anthropic's 5MB limit)\n\tjpegQuality?: number; // Default: 80\n\tincludePixelFingerprint?: boolean;\n}\n\nexport interface ResizedImage {\n\tdata: string; // base64\n\tmimeType: string;\n\toriginalWidth: number;\n\toriginalHeight: number;\n\twidth: number;\n\theight: number;\n\twasResized: boolean;\n\tfingerprint?: string;\n}\n\n// 4.5MB of base64 payload. Provides headroom below Anthropic's 5MB limit.\nconst DEFAULT_MAX_BYTES = 4.5 * 1024 * 1024;\n\nconst DEFAULT_OPTIONS: Required<ImageResizeOptions> = {\n\tmaxWidth: 2000,\n\tmaxHeight: 2000,\n\tmaxBytes: DEFAULT_MAX_BYTES,\n\tjpegQuality: 80,\n\tincludePixelFingerprint: false,\n};\n\ninterface EncodedCandidate {\n\tdata: string;\n\tencodedSize: number;\n\tmimeType: string;\n}\n\nfunction encodeCandidate(buffer: Uint8Array, mimeType: string): EncodedCandidate {\n\tconst data = Buffer.from(buffer).toString(\"base64\");\n\treturn {\n\t\tdata,\n\t\tencodedSize: Buffer.byteLength(data, \"utf-8\"),\n\t\tmimeType,\n\t};\n}\n\n/**\n * Resize an image to fit within the specified max dimensions and encoded file size.\n * Returns null if the image cannot be resized below maxBytes.\n *\n * Uses Photon (Rust/WASM) for image processing. If Photon is not available,\n * returns null.\n *\n * Strategy for staying under maxBytes:\n * 1. First resize to maxWidth/maxHeight\n * 2. Try both PNG and JPEG formats, pick the smaller one\n * 3. If still too large, try JPEG with decreasing quality\n * 4. If still too large, progressively reduce dimensions until 1x1\n */\nexport async function resizeImageInProcess(\n\tinputBytes: Uint8Array,\n\tmimeType: string,\n\toptions?: ImageResizeOptions,\n): Promise<ResizedImage | null> {\n\tconst opts = { ...DEFAULT_OPTIONS, ...options };\n\tconst inputBase64Size = Math.ceil(inputBytes.byteLength / 3) * 4;\n\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\treturn null;\n\t}\n\n\tlet image: ReturnType<typeof photon.PhotonImage.new_from_byteslice> | undefined;\n\ttry {\n\t\tconst rawImage = photon.PhotonImage.new_from_byteslice(inputBytes);\n\t\timage = applyExifOrientation(photon, rawImage, inputBytes);\n\t\tif (image !== rawImage) rawImage.free();\n\n\t\tconst originalWidth = image.get_width();\n\t\tconst originalHeight = image.get_height();\n\t\tconst format = mimeType.split(\"/\")[1] ?? \"png\";\n\t\tconst fingerprint = opts.includePixelFingerprint\n\t\t\t? createHash(\"sha256\")\n\t\t\t\t\t.update(`${originalWidth}x${originalHeight}:`)\n\t\t\t\t\t.update(image.get_raw_pixels())\n\t\t\t\t\t.digest(\"hex\")\n\t\t\t: undefined;\n\n\t\t// Check if already within all limits (dimensions AND encoded size)\n\t\tif (originalWidth <= opts.maxWidth && originalHeight <= opts.maxHeight && inputBase64Size < opts.maxBytes) {\n\t\t\treturn {\n\t\t\t\tdata: Buffer.from(inputBytes).toString(\"base64\"),\n\t\t\t\tmimeType: mimeType || `image/${format}`,\n\t\t\t\toriginalWidth,\n\t\t\t\toriginalHeight,\n\t\t\t\twidth: originalWidth,\n\t\t\t\theight: originalHeight,\n\t\t\t\twasResized: false,\n\t\t\t\t...(fingerprint ? { fingerprint } : {}),\n\t\t\t};\n\t\t}\n\n\t\t// Calculate initial dimensions respecting max limits\n\t\tlet targetWidth = originalWidth;\n\t\tlet targetHeight = originalHeight;\n\n\t\tif (targetWidth > opts.maxWidth) {\n\t\t\ttargetHeight = Math.round((targetHeight * opts.maxWidth) / targetWidth);\n\t\t\ttargetWidth = opts.maxWidth;\n\t\t}\n\t\tif (targetHeight > opts.maxHeight) {\n\t\t\ttargetWidth = Math.round((targetWidth * opts.maxHeight) / targetHeight);\n\t\t\ttargetHeight = opts.maxHeight;\n\t\t}\n\n\t\tfunction tryEncodings(width: number, height: number, jpegQualities: number[]): EncodedCandidate[] {\n\t\t\tconst resized = photon!.resize(image!, width, height, photon!.SamplingFilter.Lanczos3);\n\n\t\t\ttry {\n\t\t\t\tconst candidates: EncodedCandidate[] = [encodeCandidate(resized.get_bytes(), \"image/png\")];\n\t\t\t\tfor (const quality of jpegQualities) {\n\t\t\t\t\tcandidates.push(encodeCandidate(resized.get_bytes_jpeg(quality), \"image/jpeg\"));\n\t\t\t\t}\n\t\t\t\treturn candidates;\n\t\t\t} finally {\n\t\t\t\tresized.free();\n\t\t\t}\n\t\t}\n\n\t\tconst qualitySteps = Array.from(new Set([opts.jpegQuality, 85, 70, 55, 40]));\n\t\tlet currentWidth = targetWidth;\n\t\tlet currentHeight = targetHeight;\n\n\t\twhile (true) {\n\t\t\tconst candidates = tryEncodings(currentWidth, currentHeight, qualitySteps);\n\t\t\tfor (const candidate of candidates) {\n\t\t\t\tif (candidate.encodedSize < opts.maxBytes) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata: candidate.data,\n\t\t\t\t\t\tmimeType: candidate.mimeType,\n\t\t\t\t\t\toriginalWidth,\n\t\t\t\t\t\toriginalHeight,\n\t\t\t\t\t\twidth: currentWidth,\n\t\t\t\t\t\theight: currentHeight,\n\t\t\t\t\t\twasResized: true,\n\t\t\t\t\t\t...(fingerprint ? { fingerprint } : {}),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentWidth === 1 && currentHeight === 1) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst nextWidth = currentWidth === 1 ? 1 : Math.max(1, Math.floor(currentWidth * 0.75));\n\t\t\tconst nextHeight = currentHeight === 1 ? 1 : Math.max(1, Math.floor(currentHeight * 0.75));\n\t\t\tif (nextWidth === currentWidth && nextHeight === currentHeight) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcurrentWidth = nextWidth;\n\t\t\tcurrentHeight = nextHeight;\n\t\t}\n\n\t\treturn null;\n\t} catch {\n\t\treturn null;\n\t} finally {\n\t\tif (image) {\n\t\t\timage.free();\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,362 @@
1
+ # Image-only computer use
2
+
3
+ The image-only implementation shipped on `lunr-dev` as `0.2.21-dev.12.1`
4
+ and received user testing. Automated validation passed on the dev integration.
5
+ The stable implementation builds on that work without dev-channel naming or update
6
+ changes, and repairs failure reporting and unchanged-image detection. Smooth cursor animation is not implemented. CuaDriver 0.28.1 has production approval for lunR 0.2.26; broader hardware acceptance remains unverified.
7
+
8
+ ## Setup and permissions
9
+
10
+ Run `/computer setup` in the local lunR terminal. Setup verifies and installs the
11
+ bundled runtime without downloading code, capturing the screen, or operating an
12
+ application. It is unavailable in headless and gateway sessions.
13
+
14
+ Windows needs an active, unlocked desktop. On Apple Silicon macOS, setup prints
15
+ the exact installed `CuaDriver.app` path. Add that app to Accessibility and
16
+ Screen & System Audio Recording in System Settings > Privacy & Security, then
17
+ restart lunR. Older macOS versions call the second grant Screen Recording.
18
+ Only the user can grant these permissions. Setup leaves an existing
19
+ `/Applications/CuaDriver.app` alone.
20
+
21
+ Computer use and Allow foreground control default to on. Windows x64/arm64 and
22
+ Apple Silicon expose `computer_load`; detailed tools load on demand. Linux and
23
+ Intel macOS have no native discovery tool. All computer tools except release
24
+ require an image-capable model. There is no text-only accessibility fallback.
25
+ Gateway sessions operate the gateway host, not the chat client's device.
26
+
27
+ `computer_end` releases without approval. Read-only allows relevant observation
28
+ and release, but blocks mutation. Yolo and Auto permit input. Auto allows
29
+ requested, implied, or necessary GUI work without lunR per-call prompts. In
30
+ Yolo, ask before introducing GUI work into an otherwise non-GUI task. These
31
+ intent rules are agent guidance, not a natural-language authorization classifier.
32
+
33
+ Prefer background window input. Foreground window input requires a verified
34
+ background failure and a fresh image. Desktop input requires `desktop=true` and
35
+ `foreground=true`. Disabling foreground control blocks desktop input, foreground
36
+ window input, launch, and window management. An application can still change its
37
+ own focus after background input.
38
+
39
+ Native tools are excluded from children and refuse child execution. Children
40
+ with shell access are not OS-sandboxed. No raw driver administration, update,
41
+ recording, or permission tool is exposed.
42
+
43
+ ## Recovery contract
44
+
45
+ A failed tool result keeps its text, any recovery image, and structured outcome details together. The error flag does not mean the input had no effect. Results distinguish validation/preflight without dispatch from uncertain native delivery, and include the workflow state (`ready`, `stopped`, or `cleanup_unconfirmed`). A healthy workflow remains loaded after recoverable mistakes such as an expired or mismatched token or invalid coordinates. Use `computer_observe` directly for a new image and token; `computer_load` is not a runtime restart. Never replay an uncertain click or launch merely because the call reported an error. If the native response is settled and the target remains safe to capture, one recovery image may accompany the failure. When capture fails, do not infer the action failed or substitute another target automatically. An unavailable window calls for explicit app/window discovery or a desktop observation. Broken transport, cancellation, loss of ownership, and unconfirmed cleanup stop the workflow.
46
+
47
+ Launch takes `{name}` only, without an observation token. It may activate an existing app, start a new one, or return without a usable window. If launch status or window discovery is uncertain, try `computer_apps` with the app name or a valid positive returned PID before deciding whether to launch again. Observe an exact discovered PID and window ID before input. Launch has a separate longer native timeout budget inside the 90-second workflow limit; a timeout does not prove that the app did not start.
48
+
49
+ ## Observe, act, inspect
50
+
51
+ 1. Use `computer_apps` for app identities or windows for a PID. For a known app
52
+ or title, pass `query` to avoid paging through unrelated identities. It matches
53
+ a case-insensitive literal substring in `name`, `app_name`, or `title` before
54
+ pagination and display truncation in the requested collection: ordinary app
55
+ queries match apps, while a PID query matches that PID's windows. It does
56
+ not search every app's windows by title. `total` counts matching rows.
57
+ Omit `query` to browse all rows. With `include_windows:true`, a named app
58
+ query without `pid` also looks up windows for up to five matching running
59
+ PIDs, with at most 50 window rows. More than five matching PIDs asks for a
60
+ narrower query or an explicit PID, rather than choosing one arbitrarily.
61
+ Per-PID lookup failures and truncation are reported; an ordinary query
62
+ stays app-only and cheap. Results allowlist at most 50 rows and truncate titles to
63
+ 240 characters. Pass `next_offset` as `offset` with the same PID and query to
64
+ retrieve more matches. Lists refresh per call, so changing native order can
65
+ shift page boundaries. PID zero
66
+ identifies an installed app that is not running. Window `bounds` are native
67
+ geometry, not screenshot coordinates.
68
+ 2. Use `computer_observe` with an exact `pid` and `window_id`, or `desktop=true`.
69
+ The result contains one image and a short coordinate/token record.
70
+ 3. Choose one action from that image. Pass its `observation` token and coordinates
71
+ in the returned image. The workflow applies the mapping; do not scale twice.
72
+ 4. Inspect the post-action image before continuing. The tool executes one action
73
+ and captures the same target once, including when a settled native refusal
74
+ permits safe recovery capture. It never polls or retries input internally.
75
+ 5. Call `computer_end` when finished.
76
+
77
+ The token lasts 30 seconds, belongs to one exact target, and permits one action.
78
+ Copy it exactly, without abbreviating or reconstructing it. A failed action
79
+ consumes the active token. Capture again before any next action, including window
80
+ focus. Read-only app discovery preserves an existing token but does not renew
81
+ its original 30-second expiry. `background_unavailable` makes foreground input the next candidate after
82
+ a fresh capture, if permitted. Do not substitute another background shortcut.
83
+ Token rejection does not prove foreground typing failed.
84
+
85
+ Every new observation invalidates the previous token before capture. Failed,
86
+ cancelled, or malformed captures issue no token. Old tokens cannot be replayed,
87
+ including after a successful action returns a new image.
88
+
89
+ Supported input is single, double, and right click with modifiers, a complete
90
+ press-drag-release gesture, scrolling at image coordinates, Unicode text, and
91
+ keys or modifier shortcuts. Window text/keys can use image coordinates or the
92
+ observed focused field. Desktop text/keys use the observed focused field only;
93
+ change focus with a separate grounded click.
94
+
95
+ `computer_window` supports `frame` in native window-bounds units and `focus` on
96
+ an exact observed window. Minimize/restore uses a grounded image click on a
97
+ visible control. The pinned driver has no portable minimize/restore RPC.
98
+ `computer_launch` returns bounded app metadata, not an inferred input target;
99
+ capture an exact window before acting.
100
+
101
+ A successful transport or a changed image does not prove the intended application
102
+ effect. Results preserve partial/unverifiable outcomes and bounded refusal codes.
103
+ Pre-dispatch failures report `input:"not_dispatched"` and state that this call
104
+ sent no input. They do not establish whether earlier calls had an effect. Token
105
+ codes distinguish a missing active observation, a mismatched token, a wrong
106
+ target, and expiry only while that state is available. A closed workflow cannot
107
+ identify whether an old token was consumed or unknown. Recoverable token
108
+ rejections keep a healthy workflow open and report `input:"not_dispatched"`;
109
+ they require a fresh image rather than a new load. Once dispatch begins,
110
+ transport failure reports `input:"uncertain"` and possible effects. Neither path
111
+ retries input. Unparseable driver text is omitted rather than forwarded as a
112
+ message; structured refusal fields remain bounded and allowlisted.
113
+ When input returns but its post-image fails, the tool reports possible effects
114
+ and either allows an explicit fresh observation when safe or stops if runtime
115
+ safety cannot be confirmed. Capture again before deciding; never repeat input blindly.
116
+ After an unchanged post-image, the same action against identical captured pixels
117
+ is refused. Pixel identity hashes decoded full-image RGBA values and dimensions,
118
+ not PNG encoding bytes, before cropping or resizing. Full captures reuse the
119
+ image processor's decode, and crops reuse the existing full-image decode. Click signatures normalize omitted left-button/single-click/empty
120
+ modifier defaults and modifier order. Three consecutive unchanged full observations
121
+ stop polling in that workflow. Crops are explicit requests, not an automatic retry loop.
122
+
123
+ Partial typing retains validated `requested_chars`, `delivered_chars`, `retryable`,
124
+ and `retry_from_character` when supplied by the driver. Counts must be safe integers
125
+ within the submitted text's Unicode code-point length, capped at 20000; the retry
126
+ index must equal the delivered count. The index is zero-based in Unicode code
127
+ points, not UTF-16 units. Verify the field in a fresh image before considering a
128
+ remaining suffix. `retryable` is driver advice, not permission or proof that
129
+ repeating input is safe. The workflow never retries typing automatically.
130
+
131
+ On supported Windows x64/arm64 hosts, `computer_hover` takes exactly
132
+ `{desktop:true,foreground:true,observation,x,y}` from a fresh primary-desktop
133
+ image. It moves the real pointer without pressing a button, waits about 700 ms
134
+ with cancellation support, then returns one full-desktop post-image. A tooltip
135
+ outside a selected crop may appear in that full image. Only the visible topmost
136
+ application receives the hover, which can itself trigger application behavior;
137
+ this is not background window hover or an all-monitor capture. Foreground
138
+ control must be allowed and read-only mode blocks hover. The pinned Windows
139
+ window-scoped movement is a synthetic overlay, so lunR does not offer window
140
+ hover. macOS and unsupported platforms do not register this tool. Desktop
141
+ origin/DPI mapping and tooltip behavior still need an authorized live test.
142
+
143
+ ## Image contract and cost limits
144
+
145
+ Window capture requests `include_accessibility_tree:false` and
146
+ `include_screenshot:true`. Neither native accessibility trees nor duplicate raw
147
+ JSON reach the model. The macOS driver still reads minimal native accessibility
148
+ facts for window identity and background-input safety. Windows window discovery
149
+ can use UIA as a fallback. Image-only describes application observation sent to
150
+ the model, not the removal of every native accessibility API call.
151
+
152
+ Window capture requests a 2560-pixel maximum. The runtime can impose a lower
153
+ configured ceiling, so this is not a promised capture resolution. The workflow
154
+ checks actual PNG dimensions against native screenshot metadata and rejects
155
+ invalid frames. Primary-desktop capture is tree-free and uses the native PNG.
156
+ Desktop coordinates map back to that PNG once; macOS `scale_factor` is not an
157
+ additional multiplier.
158
+
159
+ Returned images have a maximum 1280-pixel edge, one million pixels, and 1.5 MiB
160
+ of base64 payload. The existing image processor bounds dimensions and encoding
161
+ size. The workflow refuses images it cannot decode or map. Source PNGs also have
162
+ allocation limits. These are engineering bounds, not measured token savings.
163
+
164
+ For small text or controls, request `crop:{x,y,width,height}` with the latest
165
+ observation token. The rectangle uses that returned image's pixels. The workflow
166
+ captures fresh pixels, maps the rectangle into the full capture, and sends only
167
+ the crop. Its record gives the source dimensions, crop offset, and separate x/y
168
+ ratios. Changed source dimensions or reported window bounds reject the crop;
169
+ request a full image again. Cropping cannot recover detail absent from the native
170
+ capture. Post-action captures return the full target so dialogs outside a crop
171
+ remain visible.
172
+
173
+ Saved sessions retain the returned screenshots. Provider-facing screenshot
174
+ history also accumulates until normal compaction. This change does not prune
175
+ user images, rewrite saved sessions, or implement a generic rolling history
176
+ filter. A targeted `context` hook could remove old computer screenshots while
177
+ leaving sessions intact, but a rolling cutoff changes an earlier prompt prefix
178
+ and can invalidate cached input. That tradeoff needs approved provider measurements
179
+ before adopting a retention policy. Image-only is not automatically cheaper than
180
+ text. Current cost controls bound each new payload, remove tree/JSON duplication,
181
+ and combine one action with its post-image.
182
+
183
+ ## Cursor status
184
+
185
+ Cursor animation remains a separate native-runtime decision. The inherited
186
+ runtime launch still uses `--no-overlay`. Upstream Windows drag animation uses a
187
+ timer separate from actual input, and desktop pointer movement can teleport.
188
+ This branch does not claim smooth actual-cursor motion or synchronized drag
189
+ feedback. Any eventual animation must stay local, preserve full gestures and
190
+ cancellation, and send zero intermediate frames to the model.
191
+
192
+ ## Ownership and cancellation
193
+
194
+ An OS-account lease spans observations and actions, independent of settings
195
+ profiles. Competing workflows receive busy rather than queueing. Calls within a
196
+ workflow serialize. One cross-process lock covers creation, atomic replacement,
197
+ and deletion of the owner record. A separate lock protects runtime installation.
198
+ A live owner is not displaced because its heartbeat is late.
199
+
200
+ After MCP initialization and before any driver tool dispatch, the adapter records
201
+ the transport PID and, on macOS, daemon PID. Missing identities or failed lease
202
+ updates refuse dispatch. Recovery requires both owner and recorded runtimes to
203
+ have exited. PID reuse and malformed owner records fail closed. A crash during
204
+ initialization can leave an unrecorded idle runtime that received no input.
205
+
206
+ Release, cancellation, agent end, settings changes, and session shutdown close
207
+ the owned runtime before releasing the lease. Queued work cannot survive
208
+ cancellation. Unconfirmed shutdown retains ownership. Cancellation cannot retract
209
+ already delivered input, and forced termination does not prove held input was
210
+ released. Driver-internal helper lifetime and held-input cancellation still need
211
+ native acceptance.
212
+
213
+ Gateway cron creates fresh permission contexts with the configured default mode,
214
+ without gateway approvals or its approval handler. Read-only blocks input, and
215
+ missing approval blocks operations that still require confirmation.
216
+ Session shutdown precedes disposal, even after partial extension binding failure.
217
+ TUI cron continues to use its live permission context.
218
+
219
+ ## Runtime and distribution
220
+
221
+ The development pin is [CuaDriver 0.28.1](https://github.com/trycua/cua/releases/tag/cua-driver-rs-v0.28.1),
222
+ source `d8028a7943087ee258dc1b4d19dc12a7cd27669c`. Archive identities and approval
223
+ are in `scripts/computer-use-release.json`; `release.generated.ts` derives from
224
+ it. The upstream MIT license is under `native/computer-use`. No runtime pin or
225
+ native binary changed in the image-only workflow work.
226
+
227
+ The runtime resolves the host's optional payload package or matching archive
228
+ beside a standalone executable. It verifies the archive, extracts a fresh
229
+ reference tree, and checks cached files/helpers against it. Redirected paths and
230
+ escaping symlinks are refused. Installers do not overwrite an existing runtime.
231
+ After confirming all owned processes stopped, an inactive cache can be removed
232
+ for reinstallation. Runtime code is never downloaded at first use.
233
+
234
+ Windows uses system `tar.exe` and an isolated `mcp --direct --embedded
235
+ --no-overlay` process. A hidden system PowerShell metadata probe refuses session
236
+ zero, disconnected sessions, and inaccessible/non-Default input desktops. It
237
+ never switches desktops. Both platforms isolate profiles, strip inherited
238
+ `CUA_*`, set standard permission mode, and disable telemetry/update checks.
239
+
240
+ macOS preserves the unchanged signed app at its stable lunR-owned path, verifies
241
+ its signature with `codesign --verify --deep --strict`, and launches that exact
242
+ path through `open -n -g -W -a`. A private HOME, socket, stdin FIFO, and
243
+ `--parent-liveness-stdio` isolate daemon state and lifetime. Shutdown uses the
244
+ private PID-bound endpoint and waits for the app to exit. No re-signing occurs.
245
+
246
+ Release staging creates exact-version host-specific optional payload packages.
247
+ They contain unchanged archives and no install scripts. Workspace manifests keep
248
+ unpublished payload dependencies out. Standalone asset copying selects one
249
+ opaque archive. The v0.2.26 release records production approval for the pinned
250
+ runtime; the publish workflow checks that approval before building. Dev-channel
251
+ update/publication changes were not ported here.
252
+
253
+ ## Verification and remaining acceptance
254
+
255
+ The recovery reporting, bounded window enrichment, and Windows desktop-hover
256
+ contract have offline fake-driver coverage only. The original taskbar-click
257
+ failure phase is still unproven. No new real-desktop, native-runtime, macOS,
258
+ provider-driven, or release qualification is claimed by this change.
259
+
260
+
261
+ After integrating v0.2.24 master, all five offline package builds and the Node
262
+ bundle pass. With the PR #118 baseline repairs integrated, validation passes
263
+ 391 focused tests across 31 files and eight archive/package tests. Installation and archive staging tests now create inert
264
+ fixtures, so source tests need no native release payload. The Windows installation
265
+ test exercises real extraction, locking, cache reuse, and helper-tamper rejection
266
+ without executing either fixture file. Fake-driver tests cover exact-token
267
+ rejection with zero action dispatch, background refusal followed by fresh-capture
268
+ foreground input, and uncertain or partial post-dispatch outcomes. Real PNG
269
+ fixtures reproduce encoding-independent pixel identity and preserve crop mapping.
270
+ First-paint and first-request checks pass for both browser settings; removing only
271
+ `computer_load` reproduces master's unchanged tool hashes.
272
+
273
+ All three pinned upstream archives match their committed byte counts and SHA-256
274
+ hashes. Seven public-name tarballs staged with those unchanged real payloads pass
275
+ relocated installation, first requests, all supported OS/CPU selections, omitted
276
+ optional-payload recovery, and standalone installer `npm ci --ignore-scripts`.
277
+ Staging validates rewritten JavaScript and declaration imports and exact payload
278
+ versions in both locks. These checks ran on Windows x64 without launching the
279
+ native driver; OS/CPU selection tests do not establish operation on other hardware.
280
+ Archive integrity and packaging are verified, but native signing, permission and
281
+ input acceptance remain separate. The owner approved production publication of
282
+ CuaDriver 0.28.1 with lunR 0.2.26; this does not establish operation on other hardware.
283
+
284
+ The PR also incorporates the separately tracked baseline repairs from PR #118.
285
+ That work fixes AI catalog subpath resolution in extension loading and updates
286
+ fixtures for current gateway, shutdown, provider and subscription contracts.
287
+ Its 152 focused tests across ten files pass. The complete Ubuntu log before
288
+ those repairs records 101 coding-agent failures across 27 suites and 11 AI
289
+ failures, more than the subset exposed by check annotations. Agent passes
290
+ 181/181 in that run. Clean full-suite CI still requires broader baseline work;
291
+ local Windows-only diagnostics are not evidence of Ubuntu failures.
292
+ The automated checks did not operate a desktop or launch CuaDriver.
293
+
294
+ A separately authorized Windows x64 smoke test used this branch's compiled
295
+ computer tools with the real pinned runtime. It launched a new blank Notepad
296
+ window, captured that exact window, and typed a fixed 39-character phrase using
297
+ background delivery. The post-action screenshot showed the complete expected
298
+ text and character count. The driver's outcome remained `unverifiable`; the
299
+ image established the application effect. `computer_end` confirmed shutdown and
300
+ released the desktop lease. No document was saved or installed CLI changed.
301
+ This verifies basic launch, window capture and background text input only.
302
+ A later Windows x64 test on an owned scratch Notepad window found that background
303
+ Ctrl+A failed with `tool_invocation_failed`; a fresh image showed no selection.
304
+ A fresh-token `foreground=true` retry initially returned the same XAML/UIA error.
305
+ Pinned upstream source at `d8028a7943087ee258dc1b4d19dc12a7cd27669c`
306
+ routes `hotkey` for a XAML window through UIA before checking `delivery_mode`.
307
+ This native refusal was not a `background_unavailable` code. The unchanged
308
+ screenshot established that the background shortcut had not selected the text.
309
+
310
+ The Windows workflow now sends foreground modifier shortcuts without x/y through
311
+ that pin's `press_key` with `modifiers`, whose foreground branch uses verified
312
+ window focus and SendInput. Background shortcuts, keys with image coordinates,
313
+ and non-Windows dispatch remain unchanged. On a subsequent parent-run test,
314
+ foreground Ctrl+A selected all 39 characters in the same owned Notepad scratch;
315
+ its post-action image showed the selection. Foreground Ctrl+N then opened a
316
+ blank unsaved tab in that window, leaving the earlier scratch tab intact.
317
+
318
+ The parent next cancelled a 2048-character `computer_text` call 86 ms after the
319
+ real SDK call began, while it was still pending. The result reported
320
+ `input_dispatch_failed`, `input:uncertain` and `cleanup:confirmed`. The native
321
+ runtime exited and its desktop lease was absent before a fresh workflow captured
322
+ the same owned window. That image showed exactly six characters in the new tab.
323
+ This verifies partial text input followed by in-flight cancellation, cleanup and
324
+ reacquisition, not a pre-dispatch cancellation or complete text delivery.
325
+ `computer_end` shut down the new runtime and released its lease. Both tabs
326
+ remained unsaved; other user documents were untouched. No global CLI changed.
327
+ The complete-gesture tool API did not exercise held modifier or mouse-button
328
+ release under abort, which remains unverified.
329
+
330
+ The dev integration passed all five offline package builds, the Node bundle,
331
+ 265 focused tests across 23 suites, and eight archive/package tests. A real
332
+ Photon fixture checks cropped pixels and coordinate mapping. First-paint and
333
+ first-request checks passed with the regenerated supported-host fingerprint;
334
+ removing only `computer_load` reproduced the unchanged unsupported-host baseline.
335
+ Seven local dev tarballs passed relocated installation, OS/CPU payload selection,
336
+ omitted-optional handling, and installer-lock checks. The dev publication workflow
337
+ also passed. These historical results describe the dev integration. The current branch's
338
+ stable packaging checks are recorded above.
339
+
340
+ The user reported testing the published dev build; specific applications and
341
+ scenarios were not supplied. This does not establish full platform acceptance.
342
+ Native gates remain Windows locked/UAC/integrity states, other Electron/native
343
+ apps, display scaling and moved/resized windows, Unicode, held modifier/button
344
+ release under abort, and macOS TCC/LaunchServices/FIFO/shutdown on hardware.
345
+ Provider-driven computer tool choice has not been live-qualified. Cursor/runtime
346
+ changes need a separate scoped decision before implementation. Provider token
347
+ savings remain unmeasured. An offline fake-driver discovery comparison finds a
348
+ named app at row 118 of 139 synthetic apps in one query instead of three
349
+ unfiltered pages. It
350
+ returns one identity instead of 139 and 147 result-text characters instead of
351
+ 8699. The loaded computer-tool definitions grow by 230 serialized characters;
352
+ the first-request definitions are unchanged because detailed tools load on demand.
353
+ These are call and text-payload measurements, not model tokens or billing. The
354
+ comparison uses no desktop, provider, screenshot resizing, or history pruning.
355
+
356
+ ## Privacy
357
+
358
+ Images, window titles, and typed text can enter selected-provider requests and
359
+ saved sessions. Disabling driver telemetry does not disable lunR session storage.
360
+ GUI changes are outside filesystem rollback. Application content is untrusted
361
+ task data, never authorization. OS permissions, locked desktops, UAC, and
362
+ integrity restrictions still apply.
package/docs/features.md CHANGED
@@ -87,7 +87,7 @@ Schedule examples: `every 30m`, `every 2h`, `every 1d`, a duration one-shot (`30
87
87
 
88
88
  ## Gateway for Telegram and Discord
89
89
 
90
- Run `lunr gateway setup` in your terminal. It explains bot creation and permissions, masks token entry, validates the bot identity, and asks for your user ID, project roots, saved model, and startup preference. Log in to a model provider locally with `/login` first. Setup does not create model-provider accounts.
90
+ Run `lunr gateway setup` in your terminal. Use Up/Down and Enter to choose the platform, saved token and approved-user options, default project, startup preference, provider, and model. Long lists scroll; Escape cancels. Only a new bot token, user ID, or custom folder path needs typing. Token entry stays hidden. Setup explains bot creation, validates the bot identity, and asks before saving or starting the gateway. Log in to a model provider locally with `/login` first. Setup does not create model-provider accounts.
91
91
 
92
92
  Telegram uses BotFather and long polling. Discord needs the bot and `applications.commands` installation scopes. Enable Message Content Intent for ordinary text messages. GuildMembers intent is not required. Discord registers native slash commands; Telegram registers a command menu. Both platforms use buttons for selections and approvals.
93
93
 
@@ -115,23 +115,25 @@ Login startup runs after you sign in. Boot startup runs before login and may req
115
115
 
116
116
  Encrypted home directories, missing user-service support, network restrictions, and OS permissions can prevent boot startup. Use `status`, `doctor`, and `logs` to check the installed service and bot connections. Service definitions are separate for each lunR profile. Native startup specifications have automated tests; installing and rebooting services on all three operating systems still requires host verification.
117
117
 
118
- ### Owner access
118
+ ### Gateway access
119
119
 
120
120
  Configuration lives in `~/.lunr/agent/gateway.json` and may contain bot tokens. It is written with mode 0600 where supported; Windows security follows the profile directory's ACL. Tokens are not stored in `install-features.json` or startup command arguments. Environment tokens override file tokens in this order: `LUNR_<PLATFORM>_BOT_TOKEN`, then `<PLATFORM>_BOT_TOKEN`.
121
121
 
122
122
  If you skipped your user ID during setup, message the bot privately and approve its pairing code locally:
123
123
 
124
124
  ```bash
125
- lunr gateway pair approve telegram <code> --owner
126
- lunr gateway pair approve discord <code> --owner
125
+ lunr gateway pair approve telegram <code>
126
+ lunr gateway pair approve discord <code>
127
127
  lunr gateway pair list
128
128
  ```
129
129
 
130
- Owner access includes local projects and saved TUI conversation history. Ordinary pairing, group access, and Discord roles do not grant it. Project browsing, cross-project sessions, permission changes, and file downloads require an explicitly configured owner in a private DM. Removing owner access invalidates later owner actions and approvals.
130
+ Approval grants full gateway access, including local projects, saved TUI conversations, permission changes, and file downloads. Existing paired users work immediately without pairing again or receiving a separate owner grant. User allowlists, approved chats, and Discord roles use the same access check for messages and commands. Only approve people, chats, and roles you trust with this computer. In shared chats, other members may see replies and downloaded files.
131
+
132
+ Legacy `owners` entries and the `--owner` flag remain compatible, but do not grant a separate permission level. Unapproved users remain blocked. Removing every applicable access grant prevents later commands, approvals, and result delivery. Picker and approval buttons still belong to the user who requested them; session transfer and tool permission checks remain in effect.
131
133
 
132
134
  ### Projects and mobile controls
133
135
 
134
- Use `/project` to browse approved roots, open child folders, go back, select a folder, or create one. `/project <path>` opens the browser at an approved path. The gateway remembers the selected working directory for that conversation. Project instruction files, skills, tools, and trust checks use that directory rather than the daemon's launch directory.
136
+ Approved users can send `/start` to check setup before the first task, `/model` to select an authenticated model before a task, and a normal message immediately when setup's default project remains approved. With multiple approved roots and no explicit default, choose `/project` first. Use `/project` to browse approved roots, open child folders, go back, select a folder, or create one. `/project <path>` opens the browser at an approved path. The gateway remembers the selected working directory for that conversation. Project instruction files, skills, tools, and trust checks use that directory rather than the daemon's launch directory.
135
137
 
136
138
  **The selected project is a working directory, not a shell sandbox.** Shell commands and tools can access other locations allowed by your OS account. The folder browser and `/download` check their own path boundaries, including symlinks.
137
139
 
@@ -145,7 +147,7 @@ Use `/project` to browse approved roots, open child folders, go back, select a f
145
147
 
146
148
  Upload images or documents in chat. Images reach the model as images; documents are saved under the project's `.lunr/uploads/` directory and passed to the model as paths. `/download <project-relative path>` sends a file back. Files are limited to 8 MB; common credential filenames are blocked from download. This filename check is not a content-based secret scanner. Only send files you intend to share with the chat platform.
147
149
 
148
- Extension notices and background results reach the originating conversation even after the foreground answer. Undelivered notices persist for retry. Tool approvals, pickers, and text questions do not become model prompts; they expire when the session changes. Terminal-only custom screens report that limitation rather than pretending they accepted a selection.
150
+ Foreground replies, follow-up answers, errors, and extension notices enter a disk-backed outbox before sending. Successfully sent chunks are acknowledged in order; failed sends retry up to five times per destination without blocking other chats. A failed final preview edit falls back to a full reply. Permanently failed deliveries remain in `gateway-outbox.json` with `failed: true` and an error in gateway logs for diagnosis; they do not retry forever. A send can still reach the platform just before the process exits without recording its acknowledgement, so a restart can repeat that chunk. Existing outbox entries without the newer fields remain eligible for delivery. Session changes cancel stale interactive prompts and notices, but finished assistant results still reach their originating chat when authorized. Revoked access prevents delivery. Discord role-only authorization needs a fresh inbound role check after restart before it can authorize new sends; an old stored role assertion cannot authorize outbox replay. Tool approvals, pickers, and text questions do not become model prompts; they expire when the session changes. Terminal-only custom screens report that limitation rather than pretending they accepted a selection.
149
151
 
150
152
  ### Continue between desktop and phone
151
153
 
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider",
3
- "version": "0.2.24",
3
+ "version": "0.2.26",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pi-extension-custom-provider",
9
- "version": "0.2.24",
9
+ "version": "0.2.26",
10
10
  "dependencies": {
11
11
  "@anthropic-ai/sdk": "^0.52.0"
12
12
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider-anthropic",
3
3
  "private": true,
4
- "version": "0.2.24",
4
+ "version": "0.2.26",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider-gitlab-duo",
3
3
  "private": true,
4
- "version": "0.2.24",
4
+ "version": "0.2.26",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pi-extension-gondolin",
3
- "version": "0.2.24",
3
+ "version": "0.2.26",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pi-extension-gondolin",
9
- "version": "0.2.24",
9
+ "version": "0.2.26",
10
10
  "dependencies": {
11
11
  "@earendil-works/gondolin": "0.12.0"
12
12
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-gondolin",
3
3
  "private": true,
4
- "version": "0.2.24",
4
+ "version": "0.2.26",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",