synabun 2.4.1 → 2.4.2

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 (295) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +1 -1
  3. package/browser-extension/content.js +56 -14
  4. package/browser-extension/engine.js +158 -8
  5. package/browser-extension/manifest.json +3 -1
  6. package/browser-extension/protocol.js +91 -6
  7. package/browser-extension/service-worker.js +13 -5
  8. package/browser-extension/tokens.css +1 -1
  9. package/docs/browser-extension-bridge.md +24 -4
  10. package/lib/data-home-files.js +4 -2
  11. package/lib/first-launch-protection.js +8 -2
  12. package/lib/update-snapshot.js +11 -4
  13. package/mcp-server/dist/http.d.ts.map +1 -1
  14. package/mcp-server/dist/http.js +25 -2
  15. package/mcp-server/dist/http.js.map +1 -1
  16. package/mcp-server/dist/index.d.ts.map +1 -1
  17. package/mcp-server/dist/index.js +62 -17
  18. package/mcp-server/dist/index.js.map +1 -1
  19. package/mcp-server/dist/services/browser-bench.d.ts +22 -22
  20. package/mcp-server/dist/services/memory-maintenance.d.ts +1 -0
  21. package/mcp-server/dist/services/memory-maintenance.d.ts.map +1 -1
  22. package/mcp-server/dist/services/memory-maintenance.js +34 -45
  23. package/mcp-server/dist/services/memory-maintenance.js.map +1 -1
  24. package/mcp-server/dist/services/memory-migration-copy.d.ts +144 -0
  25. package/mcp-server/dist/services/memory-migration-copy.d.ts.map +1 -0
  26. package/mcp-server/dist/services/memory-migration-copy.js +467 -0
  27. package/mcp-server/dist/services/memory-migration-copy.js.map +1 -0
  28. package/mcp-server/dist/services/memory-migration-worker.d.ts +2 -0
  29. package/mcp-server/dist/services/memory-migration-worker.d.ts.map +1 -0
  30. package/mcp-server/dist/services/memory-migration-worker.js +60 -0
  31. package/mcp-server/dist/services/memory-migration-worker.js.map +1 -0
  32. package/mcp-server/dist/services/memory-retrieval.d.ts +4 -0
  33. package/mcp-server/dist/services/memory-retrieval.d.ts.map +1 -1
  34. package/mcp-server/dist/services/memory-retrieval.js +188 -40
  35. package/mcp-server/dist/services/memory-retrieval.js.map +1 -1
  36. package/mcp-server/dist/services/memory-schema.d.ts +58 -2
  37. package/mcp-server/dist/services/memory-schema.d.ts.map +1 -1
  38. package/mcp-server/dist/services/memory-schema.js +190 -13
  39. package/mcp-server/dist/services/memory-schema.js.map +1 -1
  40. package/mcp-server/dist/services/memory-sessions.d.ts +19 -1
  41. package/mcp-server/dist/services/memory-sessions.d.ts.map +1 -1
  42. package/mcp-server/dist/services/memory-sessions.js +56 -20
  43. package/mcp-server/dist/services/memory-sessions.js.map +1 -1
  44. package/mcp-server/dist/services/memory-verification.d.ts.map +1 -1
  45. package/mcp-server/dist/services/memory-verification.js +8 -5
  46. package/mcp-server/dist/services/memory-verification.js.map +1 -1
  47. package/mcp-server/dist/services/neural-interface.d.ts +5 -0
  48. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  49. package/mcp-server/dist/services/neural-interface.js +19 -2
  50. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  51. package/mcp-server/dist/services/retrieval-reader-worker.d.ts +2 -0
  52. package/mcp-server/dist/services/retrieval-reader-worker.d.ts.map +1 -0
  53. package/mcp-server/dist/services/retrieval-reader-worker.js +76 -0
  54. package/mcp-server/dist/services/retrieval-reader-worker.js.map +1 -0
  55. package/mcp-server/dist/services/retrieval-reader.d.ts +38 -0
  56. package/mcp-server/dist/services/retrieval-reader.d.ts.map +1 -0
  57. package/mcp-server/dist/services/retrieval-reader.js +145 -0
  58. package/mcp-server/dist/services/retrieval-reader.js.map +1 -0
  59. package/mcp-server/dist/services/sqlite-write.d.ts +14 -0
  60. package/mcp-server/dist/services/sqlite-write.d.ts.map +1 -0
  61. package/mcp-server/dist/services/sqlite-write.js +94 -0
  62. package/mcp-server/dist/services/sqlite-write.js.map +1 -0
  63. package/mcp-server/dist/services/sqlite.d.ts +39 -0
  64. package/mcp-server/dist/services/sqlite.d.ts.map +1 -1
  65. package/mcp-server/dist/services/sqlite.js +249 -8
  66. package/mcp-server/dist/services/sqlite.js.map +1 -1
  67. package/mcp-server/dist/services/tool-catalog.d.ts +1 -1
  68. package/mcp-server/dist/services/typesafe-config.d.ts +7 -1
  69. package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
  70. package/mcp-server/dist/services/typesafe-config.js +32 -10
  71. package/mcp-server/dist/services/typesafe-config.js.map +1 -1
  72. package/mcp-server/dist/services/typesafe.d.ts.map +1 -1
  73. package/mcp-server/dist/services/typesafe.js +9 -7
  74. package/mcp-server/dist/services/typesafe.js.map +1 -1
  75. package/mcp-server/dist/services/vector-cache.d.ts +32 -0
  76. package/mcp-server/dist/services/vector-cache.d.ts.map +1 -1
  77. package/mcp-server/dist/services/vector-cache.js +161 -8
  78. package/mcp-server/dist/services/vector-cache.js.map +1 -1
  79. package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
  80. package/mcp-server/dist/tools/agents.d.ts +11 -7
  81. package/mcp-server/dist/tools/agents.d.ts.map +1 -1
  82. package/mcp-server/dist/tools/agents.js +27 -9
  83. package/mcp-server/dist/tools/agents.js.map +1 -1
  84. package/mcp-server/dist/tools/browser-advanced.d.ts +1 -1
  85. package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
  86. package/mcp-server/dist/tools/browser-advanced.js +10 -3
  87. package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
  88. package/mcp-server/dist/tools/browser-extension-setup.d.ts +5 -0
  89. package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -0
  90. package/mcp-server/dist/tools/browser-extension-setup.js +23 -0
  91. package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -0
  92. package/mcp-server/dist/tools/browser-interact.d.ts.map +1 -1
  93. package/mcp-server/dist/tools/browser-interact.js +6 -1
  94. package/mcp-server/dist/tools/browser-interact.js.map +1 -1
  95. package/mcp-server/dist/tools/fb-groups.d.ts +2 -2
  96. package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
  97. package/mcp-server/dist/tools/tool-groups.d.ts +1 -1
  98. package/mcp-server/package-lock.json +2 -2
  99. package/mcp-server/package.json +1 -1
  100. package/mcp-server/src/http.ts +20 -2
  101. package/mcp-server/src/index.ts +59 -17
  102. package/mcp-server/src/services/memory-maintenance.ts +31 -28
  103. package/mcp-server/src/services/memory-migration-copy.ts +419 -0
  104. package/mcp-server/src/services/memory-migration-worker.ts +55 -0
  105. package/mcp-server/src/services/memory-retrieval.ts +173 -32
  106. package/mcp-server/src/services/memory-schema.ts +194 -12
  107. package/mcp-server/src/services/memory-sessions.ts +54 -21
  108. package/mcp-server/src/services/memory-verification.ts +7 -4
  109. package/mcp-server/src/services/neural-interface.ts +22 -2
  110. package/mcp-server/src/services/retrieval-reader-worker.ts +67 -0
  111. package/mcp-server/src/services/retrieval-reader.ts +131 -0
  112. package/mcp-server/src/services/sqlite-write.ts +60 -0
  113. package/mcp-server/src/services/sqlite.ts +246 -8
  114. package/mcp-server/src/services/typesafe-config.ts +25 -6
  115. package/mcp-server/src/services/typesafe.ts +9 -7
  116. package/mcp-server/src/services/vector-cache.ts +154 -9
  117. package/mcp-server/src/tools/agents.ts +26 -9
  118. package/mcp-server/src/tools/browser-advanced.ts +10 -3
  119. package/mcp-server/src/tools/browser-extension-setup.ts +30 -0
  120. package/mcp-server/src/tools/browser-interact.ts +5 -1
  121. package/neural-interface/i18n/en.json +263 -1
  122. package/neural-interface/i18n/pt-BR.json +264 -2
  123. package/neural-interface/lib/agents/split.js +32 -4
  124. package/neural-interface/lib/assistant-api.js +19 -8
  125. package/neural-interface/lib/assistant-brains/claude.js +2 -0
  126. package/neural-interface/lib/assistant-catalog.js +2 -2
  127. package/neural-interface/lib/assistant-config.js +0 -7
  128. package/neural-interface/lib/assistant-dispatch.js +257 -95
  129. package/neural-interface/lib/assistant-persona.js +16 -4
  130. package/neural-interface/lib/assistant-pricing.js +65 -14
  131. package/neural-interface/lib/assistant-router.js +131 -47
  132. package/neural-interface/lib/assistant-run-wait.js +45 -28
  133. package/neural-interface/lib/assistant-runtime.js +39 -33
  134. package/neural-interface/lib/backup-contents.js +158 -0
  135. package/neural-interface/lib/backup-crypto-io.js +330 -0
  136. package/neural-interface/lib/backup-crypto-worker.js +130 -0
  137. package/neural-interface/lib/backup-crypto.js +525 -0
  138. package/neural-interface/lib/backup-download.js +268 -0
  139. package/neural-interface/lib/backup-encryption.js +318 -0
  140. package/neural-interface/lib/backup-groups.js +287 -0
  141. package/neural-interface/lib/backup-restore-session.js +176 -0
  142. package/neural-interface/lib/backup-restore-stage.js +60 -0
  143. package/neural-interface/lib/backup-service.js +788 -233
  144. package/neural-interface/lib/backup-zip-reader.js +30 -18
  145. package/neural-interface/lib/backup-zip-writer.js +34 -10
  146. package/neural-interface/lib/browser-extension-adapter.js +89 -13
  147. package/neural-interface/lib/browser-extension-bridge.js +18 -7
  148. package/neural-interface/lib/claude-agent-bridge.js +1 -0
  149. package/neural-interface/lib/claude-session-cleanup.js +5 -1
  150. package/neural-interface/lib/cli-update-planner.js +105 -6
  151. package/neural-interface/lib/client-diagnostics.js +42 -0
  152. package/neural-interface/lib/confined-fs.js +7 -2
  153. package/neural-interface/lib/coordination/README.md +8 -2
  154. package/neural-interface/lib/coordination/contract.js +161 -0
  155. package/neural-interface/lib/coordination/database.js +999 -0
  156. package/neural-interface/lib/coordination/operations.js +436 -0
  157. package/neural-interface/lib/coordination/service.js +68 -537
  158. package/neural-interface/lib/coordination/storage-worker.js +101 -0
  159. package/neural-interface/lib/coordination/store.js +219 -1111
  160. package/neural-interface/lib/db.js +70 -32
  161. package/neural-interface/lib/health-count.js +37 -0
  162. package/neural-interface/lib/loop-stall.js +139 -0
  163. package/neural-interface/lib/maritaca/client.js +2 -2
  164. package/neural-interface/lib/maritaca/models.js +12 -17
  165. package/neural-interface/lib/maritaca/opencode.js +4 -2
  166. package/neural-interface/lib/memory-api.js +9 -1
  167. package/neural-interface/lib/memory-session-capture.js +42 -10
  168. package/neural-interface/lib/memory-store-gate.js +313 -0
  169. package/neural-interface/lib/memory-store-migrate.js +65 -0
  170. package/neural-interface/lib/memory-timers.js +7 -7
  171. package/neural-interface/lib/native-loop-providers.js +13 -16
  172. package/neural-interface/lib/native-loop-runtime.js +28 -7
  173. package/neural-interface/lib/opencode-build-preflight.js +18 -1
  174. package/neural-interface/lib/opencode-native-boundary.js +69 -8
  175. package/neural-interface/lib/opencode-provider-view.js +14 -3
  176. package/neural-interface/lib/opencode-v2-ws-requests.js +31 -1
  177. package/neural-interface/lib/opencode2-client.js +2 -1
  178. package/neural-interface/lib/recall-impact.js +122 -0
  179. package/neural-interface/lib/scratch-evidence.js +420 -0
  180. package/neural-interface/lib/scratch-process-guard.js +139 -0
  181. package/neural-interface/lib/scratch-references.js +279 -0
  182. package/neural-interface/lib/scratch-retention-core.js +385 -0
  183. package/neural-interface/lib/scratch-retention-worker.js +37 -0
  184. package/neural-interface/lib/scratch-retention.js +151 -0
  185. package/neural-interface/lib/session-cache-builder.js +31 -43
  186. package/neural-interface/lib/session-cache-worker.js +157 -0
  187. package/neural-interface/lib/session-indexer.js +28 -21
  188. package/neural-interface/lib/session-search-index.js +85 -0
  189. package/neural-interface/lib/skills/creation.js +1 -1
  190. package/neural-interface/lib/sqlite-integrity-worker.js +3 -1
  191. package/neural-interface/lib/style-guide/store.js +43 -3
  192. package/neural-interface/lib/system-restore.js +50 -0
  193. package/neural-interface/lib/teams/api.js +15 -6
  194. package/neural-interface/lib/teams/claims.js +67 -31
  195. package/neural-interface/lib/teams/index.js +7 -7
  196. package/neural-interface/lib/teams/integration.js +40 -40
  197. package/neural-interface/lib/teams/landing.js +6 -6
  198. package/neural-interface/lib/teams/recovery.js +24 -23
  199. package/neural-interface/lib/teams/scheduler.js +194 -95
  200. package/neural-interface/lib/teams/state.js +14 -14
  201. package/neural-interface/lib/teams/worktrees.js +27 -27
  202. package/neural-interface/lib/whatsapp/bridge.js +2 -1
  203. package/neural-interface/lib/worker-confinement.js +47 -2
  204. package/neural-interface/lib/worker-mcp-channel.js +2 -0
  205. package/neural-interface/lib/worker-resume.js +5 -0
  206. package/neural-interface/lib/worker-stop.js +86 -0
  207. package/neural-interface/package-lock.json +2 -2
  208. package/neural-interface/package.json +1 -1
  209. package/neural-interface/public/index.html +233 -24
  210. package/neural-interface/public/onboarding.html +259 -34
  211. package/neural-interface/public/shared/agents/studio/ax-library.js +0 -6
  212. package/neural-interface/public/shared/agents/studio/ax-main.js +14 -7
  213. package/neural-interface/public/shared/agy/agy-options.js +11 -0
  214. package/neural-interface/public/shared/agy/agy-panel.js +29 -10
  215. package/neural-interface/public/shared/agy/agy-styles.js +14 -12
  216. package/neural-interface/public/shared/agy/agy-tabs-logic.js +4 -1
  217. package/neural-interface/public/shared/api.js +1 -1
  218. package/neural-interface/public/shared/assistant/asst-api.js +3 -3
  219. package/neural-interface/public/shared/assistant/asst-brain-picker.js +13 -6
  220. package/neural-interface/public/shared/assistant/asst-control.js +2 -0
  221. package/neural-interface/public/shared/assistant/asst-motion-gate.js +78 -4
  222. package/neural-interface/public/shared/assistant/asst-panel.js +18 -2
  223. package/neural-interface/public/shared/assistant/asst-rack-styles.js +4 -0
  224. package/neural-interface/public/shared/assistant/asst-render.js +105 -38
  225. package/neural-interface/public/shared/assistant/asst-route.js +100 -21
  226. package/neural-interface/public/shared/assistant/asst-routes-editor.js +1 -1
  227. package/neural-interface/public/shared/assistant/asst-sidepanel.js +4 -2
  228. package/neural-interface/public/shared/assistant/asst-state.js +11 -0
  229. package/neural-interface/public/shared/assistant/asst-styles.js +10 -23
  230. package/neural-interface/public/shared/assistant/route-identity.js +2 -1
  231. package/neural-interface/public/shared/cdx/cdx-render.js +9 -0
  232. package/neural-interface/public/shared/cdx/cdx-settings.js +3 -1
  233. package/neural-interface/public/shared/cdx/cdx-styles.js +6 -0
  234. package/neural-interface/public/shared/cdx/cdx-tabs.js +29 -9
  235. package/neural-interface/public/shared/client-diagnostics.js +94 -0
  236. package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
  237. package/neural-interface/public/shared/cp/cp-styles.js +1 -1
  238. package/neural-interface/public/shared/effort-i18n.js +118 -0
  239. package/neural-interface/public/shared/html-shell.js +4 -52
  240. package/neural-interface/public/shared/loading-diagnostic-entry.js +64 -0
  241. package/neural-interface/public/shared/memory-store-wait.js +52 -0
  242. package/neural-interface/public/shared/morelogin-profile-field.js +1 -1
  243. package/neural-interface/public/shared/mtc/mtc-logic.js +2 -1
  244. package/neural-interface/public/shared/mtc/mtc-panel.js +8 -1
  245. package/neural-interface/public/shared/mtc/mtc-styles.js +13 -12
  246. package/neural-interface/public/shared/ocp-v2/ocp-v2-childpanel.js +7 -0
  247. package/neural-interface/public/shared/ocp-v2/ocp-v2-location-logic.js +109 -0
  248. package/neural-interface/public/shared/ocp-v2/ocp-v2-modelpicker.js +8 -1
  249. package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +118 -6
  250. package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +27 -3
  251. package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +13 -0
  252. package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +2 -1
  253. package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +27 -93
  254. package/neural-interface/public/shared/ocp-v2/ocp-v2-variantpicker.js +17 -6
  255. package/neural-interface/public/shared/output-format.js +294 -0
  256. package/neural-interface/public/shared/provider-icons.js +6 -0
  257. package/neural-interface/public/shared/schedules-view.js +2 -1
  258. package/neural-interface/public/shared/server-presence.js +77 -0
  259. package/neural-interface/public/shared/settings/settings-backup-contents.js +241 -0
  260. package/neural-interface/public/shared/settings/settings-backup-download.js +298 -0
  261. package/neural-interface/public/shared/settings/settings-backup-encryption-pane.js +335 -0
  262. package/neural-interface/public/shared/settings/settings-backup-encryption.js +545 -0
  263. package/neural-interface/public/shared/settings/settings-ia.js +1 -1
  264. package/neural-interface/public/shared/skills/studio/sx-geometry.js +12 -3
  265. package/neural-interface/public/shared/skills/studio/sx-main.js +14 -7
  266. package/neural-interface/public/shared/studio-attention.js +6 -0
  267. package/neural-interface/public/shared/styles.css +341 -437
  268. package/neural-interface/public/shared/transcript-rows.js +28 -3
  269. package/neural-interface/public/shared/tray-auto-close.js +18 -5
  270. package/neural-interface/public/shared/ui-agents.js +1 -2
  271. package/neural-interface/public/shared/ui-automation-studio.js +168 -108
  272. package/neural-interface/public/shared/ui-claude-panel.js +42 -65
  273. package/neural-interface/public/shared/ui-loading.js +124 -17
  274. package/neural-interface/public/shared/ui-native-loop-router.js +10 -0
  275. package/neural-interface/public/shared/ui-navbar.js +2 -1
  276. package/neural-interface/public/shared/ui-output.js +533 -0
  277. package/neural-interface/public/shared/ui-schedules-studio.js +165 -128
  278. package/neural-interface/public/shared/ui-scroll-follow.js +97 -6
  279. package/neural-interface/public/shared/ui-sessions.js +2 -2
  280. package/neural-interface/public/shared/ui-settings-entry.js +18 -0
  281. package/neural-interface/public/shared/ui-settings.js +224 -65
  282. package/neural-interface/public/shared/ui-sidepanel-tray.js +3 -2
  283. package/neural-interface/public/shared/ui-tooltip.js +16 -0
  284. package/neural-interface/public/shared/ui-tutorial.js +5 -6
  285. package/neural-interface/public/shared/ui-worker-end.js +27 -8
  286. package/neural-interface/public/shared/worker-end.js +9 -4
  287. package/neural-interface/public/variant/2d/main.js +5 -0
  288. package/neural-interface/public/variant/3d/app.js +10 -0
  289. package/neural-interface/public/variant/3d/main.js +5 -1
  290. package/neural-interface/scripts/scratch-retention.mjs +20 -0
  291. package/neural-interface/server.js +477 -139
  292. package/npm-shrinkwrap.json +2 -2
  293. package/package.json +1 -1
  294. package/scripts/restore-data-home-from-backup.mjs +175 -8
  295. package/setup.js +18 -4
package/CHANGELOG.md CHANGED
@@ -1,3 +1,33 @@
1
+ # SynaBun v.2.4.2
2
+
3
+ This release gives you control over your backups, with optional password protection and a choice of what each one contains. It also makes side panels easier to read and fixes problems with restarts, large memory databases and OpenCode.
4
+
5
+ ## ✨ New
6
+
7
+ - **Password protection for backups.** Turn it on in Settings under Memory & backups. Manual, scheduled and pre-update backups are then encrypted, and scheduled backups keep running without asking for the password. It is off by default, and your existing backups still restore as before.
8
+ - **Choose what a backup contains.** Each group of data has its own switch and shows its size, so you can leave out caches and working folders that made backups very large. Logs and browser profiles are no longer included. A running backup can now be cancelled.
9
+ - **Save backups to a folder you choose.** Download full backup now writes directly to that folder and shows its progress, so large backups no longer have to fit in the browser tab first.
10
+ - **Page scripts in your everyday browser.** Browser Bridge 1.4.0 lets agents run page scripts and wait for a page to finish loading. To use it, reload the extension, turn on Allow User Scripts in its details, and reload it once more.
11
+
12
+ ## 🛠 Fixed
13
+
14
+ - **Workers survive a restart.** Workers paused for a server restart are no longer recorded as stopped by you, and they resume when the server is back.
15
+ - **Safer database upgrades.** Only one process now makes the safety copy before a memory database upgrade. Large databases no longer fill the disk with duplicate copies or block SynaBun from starting.
16
+ - **No more false "Server offline" screen.** A server that is only busy, for example during a large backup, no longer shows as offline.
17
+ - **OpenCode recovers from a removed folder.** If a session's folder is gone, the panel starts a new session in the right project and puts your prompt back in the box. OpenCode updates now show the update badge too.
18
+ - **Side panels stay at the bottom.** Transcripts keep following new output when the composer resizes, content collapses or the browser zoom changes.
19
+ - **Planned team tasks start reliably.** A task approved with a long slice title no longer fails when its team starts.
20
+
21
+ ## ⚙️ Changed
22
+
23
+ - **Side panel output is easier to read.** All six panels now share the same text, table and code styling. Wide tables scroll inside their frame and can be copied or expanded.
24
+ - **Studio windows open at a consistent size.** Skills, Agents, Automation and Schedules all open at the same default size and keep their saved position.
25
+ - **Model choices wait for you.** A route card now stays open until you answer it, instead of expiring after a set time.
26
+ - **Updated model pricing.** Prices were refreshed across all worker providers, so usage costs are more accurate.
27
+ - **More of the interface in Portuguese.** Backup messages, route cards and reasoning effort labels now appear in Brazilian Portuguese.
28
+
29
+ ---
30
+
1
31
  # SynaBun v.2.4.1
2
32
 
3
33
  The Assistant can now use a specialist for each type of task. This release also expands file uploads in the Chrome extension and makes desktop startup failures easier to recover from.
package/README.md CHANGED
@@ -178,7 +178,7 @@ Everything SynaBun stores is in one folder outside the app: `~/.synabun` on macO
178
178
 
179
179
  ## Links
180
180
 
181
- - [Changelog](./CHANGELOG.md): what is new in 2.4.1 and before
181
+ - [Changelog](./CHANGELOG.md): what is new in 2.4.2 and before
182
182
  - [Security](./SECURITY.md): security model and how to report a vulnerability
183
183
  - [Contributing](./CONTRIBUTING.md): bug reports and feature requests are welcome as [issues](https://github.com/danilokhury/Synabun/issues); pull requests are not accepted
184
184
  - [Website](https://synabun.ai), [docs](https://synabun.ai/docs) and [blog](https://synabun.ai/blog)
@@ -15,7 +15,22 @@
15
15
  };
16
16
  const observer = new MutationObserver(removed);
17
17
  observer.observe(document, { childList: true, subtree: true });
18
- function target(args, active = false) {
18
+ // Uploads stay in the approved origin. Open shadow roots and same-origin frames can own hidden inputs.
19
+ function uploadMatches(selector) {
20
+ const matches = [], roots = [document];
21
+ for (const root of roots) {
22
+ for (const match of root.querySelectorAll(selector)) matches.push(match);
23
+ for (const node of root.querySelectorAll('*')) {
24
+ if (node.shadowRoot) roots.push(node.shadowRoot);
25
+ if (node.localName === 'iframe') {
26
+ const doc = node.contentDocument;
27
+ if (doc && doc.defaultView?.origin === location.origin) roots.push(doc);
28
+ }
29
+ }
30
+ }
31
+ return matches;
32
+ }
33
+ function target(args, active = false, query = selector => document.querySelectorAll(selector)) {
19
34
  removed(observer.takeRecords());
20
35
  if (args.ref) {
21
36
  const el = refs.get(args.ref);
@@ -23,7 +38,7 @@
23
38
  return el;
24
39
  }
25
40
  if (!args.selector && active) return document.activeElement;
26
- const found = [...document.querySelectorAll(args.selector || 'body')];
41
+ const found = query(args.selector || 'body');
27
42
  if (!found.length) error('NO_MATCH');
28
43
  if (found.length > 1 && args.nthMatch === undefined) error('AMBIGUOUS_TARGET');
29
44
  const el = found[args.nthMatch || 0]; if (!el) error('NO_MATCH'); return el;
@@ -60,6 +75,41 @@
60
75
  else if (!sites.includes(location.origin)) error('SITE_NOT_APPROVED');
61
76
  }
62
77
  const event = (el, name) => el.dispatchEvent(new Event(name, { bubbles: true }));
78
+ function acceptsFile(file, spec) {
79
+ const tokens = (spec || '').toLowerCase().split(',').map(s => s.trim()).filter(Boolean);
80
+ return !tokens.length || tokens.some(token => token === '*/*' || token === file.type ||
81
+ (token.startsWith('.') && file.name.toLowerCase().endsWith(token)) ||
82
+ (token.endsWith('/*') && file.type.startsWith(token.slice(0, -1))));
83
+ }
84
+ function uploadFiles(args, due) {
85
+ const parts = uploadParts.get(args.uploadId);
86
+ uploadParts.delete(args.uploadId);
87
+ if (!args.metadata || args.metadata.length !== args.files.length) error('UPLOAD_METADATA_UNAVAILABLE');
88
+ // Resolve the current input after the last async transfer. Keep selection and dispatch in its realm.
89
+ const el = target(args, false, uploadMatches);
90
+ if (args.ref && el.ownerDocument !== document) error('STALE_REF');
91
+ safeNode(el);
92
+ if (!el.matches('input[type=file]')) error('NO_MATCH');
93
+ if (el.matches(':disabled')) error('UPLOAD_DISABLED');
94
+ if (!el.multiple && args.files.length > 1) error('UPLOAD_MULTIPLE');
95
+ const view = el.ownerDocument.defaultView;
96
+ const transfer = new view.DataTransfer();
97
+ args.files.forEach((name, index) => {
98
+ const { size, type, lastModified } = args.metadata[index];
99
+ const file = new view.File(parts?.[index] || [], name, { type, lastModified });
100
+ if (file.size !== size) error('OPERATION_FAILED');
101
+ if (!acceptsFile(file, el.accept)) error('UPLOAD_ACCEPT_MISMATCH');
102
+ transfer.items.add(file);
103
+ });
104
+ due();
105
+ el.files = transfer.files;
106
+ // Take the receipt before a synchronous change listener consumes the selection or clears the control.
107
+ const files = Array.from(el.files, ({ name, type, size }) => ({ name, type, size }));
108
+ if (files.length !== args.files.length || files.some((file, i) =>
109
+ file.name !== args.files[i] || file.type !== args.metadata[i].type || file.size !== args.metadata[i].size)) error('UPLOAD_ASSIGNMENT_FAILED');
110
+ for (const name of ['input', 'change']) el.dispatchEvent(new view.Event(name, { bubbles: true, composed: true }));
111
+ return files;
112
+ }
63
113
  function setValue(el, value) {
64
114
  safeNode(el);
65
115
  if (el.isContentEditable) el.textContent = value;
@@ -129,6 +179,10 @@
129
179
  due(); el.scrollBy({ top: ['up', 'down'].includes(args.direction) ? amount * (args.direction === 'up' ? -1 : 1) : 0,
130
180
  left: ['left', 'right'].includes(args.direction) ? amount * (args.direction === 'left' ? -1 : 1) : 0, behavior: 'instant' }); return state();
131
181
  }
182
+ if (op === 'upload') {
183
+ const files = uploadFiles(args, due);
184
+ return { ...state(), files };
185
+ }
132
186
  const el = target(args, ['type', 'press'].includes(op)); safeNode(el);
133
187
  if (op === 'click') {
134
188
  const link = el.closest('a[href]'); if (link) {
@@ -151,18 +205,6 @@
151
205
  if (!['Enter', 'Escape', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Tab', 'Backspace', 'Delete'].includes(args.key)) error('UNSUPPORTED_IN_EXTENSION_MODE');
152
206
  due(); el.dispatchEvent(new KeyboardEvent('keydown', { key: args.key, bubbles: true }));
153
207
  el.dispatchEvent(new KeyboardEvent('keyup', { key: args.key, bubbles: true }));
154
- } else if (op === 'upload') {
155
- if (!el.matches('input[type=file]')) error('NO_MATCH');
156
- const transfer = new DataTransfer();
157
- if (!el.multiple && args.files.length > 1) error('UPLOAD_MULTIPLE');
158
- const parts = uploadParts.get(args.uploadId);
159
- uploadParts.delete(args.uploadId);
160
- args.files.forEach((name, index) => {
161
- const file = new File(parts?.[index] || [], name, { type: 'application/octet-stream' });
162
- if (file.size !== args.sizes[index]) error('OPERATION_FAILED');
163
- transfer.items.add(file);
164
- });
165
- due(); el.files = transfer.files; event(el, 'input'); event(el, 'change');
166
208
  } else error('UNSUPPORTED_IN_EXTENSION_MODE');
167
209
  return state();
168
210
  }
@@ -1,12 +1,41 @@
1
- import { anyOrigin, command, CONTROL, controlSurface, fail, HISTORY, inventory, hostPattern, localDeadline, MAX_FILE, MAX_TABS, nonce, publicOrigin, safeError } from './protocol.js';
1
+ import { anyOrigin, command, CONTROL, controlSurface, ERROR_TEXT, EVALUATE_RESULT_MAX, fail, HISTORY, inventory, hostPattern, localDeadline, longBudget, MAX_FILE, MAX_TABS, NETWORK_IDLE_QUIET, nonce, publicOrigin, safeError } from './protocol.js';
2
+
3
+ // The script handed to chrome.userScripts.execute for `evaluate`: the agent's code inside a wrapper that awaits it,
4
+ // turns what it returns into JSON text (cut at `cap` characters) and reports what it throws, so the answer is always
5
+ // this envelope and never a live object of the page. The arguments are parsed here and written back as JSON, so the
6
+ // script holds nothing but that data and the agent's own code. No string is ever evaluated by the extension itself:
7
+ // the browser compiles the script in the page (or in the user-script world), where the owner allowed user scripts.
8
+ // An expression that evaluates to a function is called with the arguments (as Playwright does for a string); a body
9
+ // is the body of an async function whose parameter `args` is the array of arguments.
10
+ function pageScript(args, cap) {
11
+ const list = JSON.stringify(args.params === undefined ? [] : JSON.parse(args.params));
12
+ const call = args.body !== undefined
13
+ ? `(async function (args) {\n${args.body}\n}).call(undefined, __synabunArgs)`
14
+ : `(__synabunValue => typeof __synabunValue === 'function' ? __synabunValue.apply(undefined, __synabunArgs) : __synabunValue)((\n${args.expression.replace(/[\s;]+$/, '')}\n))`;
15
+ return `(async () => { const __synabunArgs = ${list}; try { const __synabunResult = await ${call}; `
16
+ + `let __synabunJson = JSON.stringify(__synabunResult); if (typeof __synabunJson !== 'string') __synabunJson = 'null'; `
17
+ + `return { synabun: 1, ok: true, json: __synabunJson.length > ${cap} ? __synabunJson.slice(0, ${cap}) : __synabunJson, length: __synabunJson.length }; } `
18
+ + `catch (__synabunError) { return { synabun: 1, ok: false, name: String(__synabunError && __synabunError.name || '').slice(0, 200), `
19
+ + `message: String(__synabunError && __synabunError.message !== undefined ? __synabunError.message : __synabunError).slice(0, 2000), `
20
+ + `stack: String(__synabunError && __synabunError.stack || '').slice(0, 6000) }; } })()`;
21
+ }
22
+ // The result's JSON text as it travels: at most `cap` characters, and few enough bytes for one bridge message.
23
+ const RESULT_BYTES = 2500000;
24
+ function clipped(text, cap) {
25
+ let out = text.length > cap ? text.slice(0, cap) : text;
26
+ for (let size = new TextEncoder().encode(out).length; size > RESULT_BYTES; size = new TextEncoder().encode(out).length) out = out.slice(0, Math.floor(out.length * RESULT_BYTES / size) - 1);
27
+ return out;
28
+ }
2
29
 
3
30
  /** Pure controller over an injected chrome API; no socket or storage credential access. */
4
31
  // `now` is a monotonic clock (milliseconds) for command deadlines; `wallClock` the system clock the content script shares.
5
32
  // `fullControlDefault` is the mode before the owner ever chose one (full control: agents may use any http(s) site and
6
33
  // any tab of this browser with no sharing step). `activateMs` is how long a full-control screenshot lets a tab it
7
- // brought to the front settle before capturing it.
34
+ // brought to the front settle before capturing it. `idleMs` is how long a tab must have had no request in flight to be
35
+ // network-idle (a load-state wait).
8
36
  export function createEngine(chrome, { readUpload, save = async () => {}, changed = () => {}, settleMs = 10000, quietMs = 500, pollMs = 50,
9
- now = () => performance.now(), wallClock = () => Date.now(), fullControlDefault = true, activateMs = 150, commitMs = 20000, visibleMs = 2000 } = {}) {
37
+ now = () => performance.now(), wallClock = () => Date.now(), fullControlDefault = true, activateMs = 150, commitMs = 20000, visibleMs = 2000,
38
+ idleMs = NETWORK_IDLE_QUIET } = {}) {
10
39
  // `epoch` moves only on the owner's revocations and pairing changes, and cancels every tab's work. A tab's own
11
40
  // navigation, update or close moves that tab's counter in `moves` (by Chrome tab id) and nothing else: one agent's
12
41
  // ordinary navigation never cancels another agent's work on another tab. `focus` moves when the active tab changes;
@@ -51,7 +80,38 @@ export function createEngine(chrome, { readUpload, save = async () => {}, change
51
80
  return inventory({ tabs: listed.map(t => ({ handle: t.handle, url: t.url, owner: t.owner, created: t.created === true, title: clip(t.title) })),
52
81
  sites: [...sites], versions: sites.map(s => versions.get(s) || 0), allowNewTabs, uploads: true, downloads, fullControl, modeVersion });
53
82
  };
54
- const persist = async () => { await save({ tabs: [...tabs.values()], sites, versions: [...versions], allowNewTabs, uploads: true, downloads, fullControl, modeVersion }); changed(current()); };
83
+ // ── The network watch, for a wait with loadState 'networkidle' ──
84
+ // Only a tab an agent holds is watched: three non-blocking webRequest listeners, filtered to that tab, added when an
85
+ // agent takes it and removed when it gives it back, the tab closes or the owner takes it back (rewatch(), on every
86
+ // change of the tabs). Nothing of a request is kept but its id, and the owner's other tabs are never observed.
87
+ // `quietSince` is when the tab last had no request in flight (or when the watch began).
88
+ const web = chrome.webRequest, watchable = !!(web?.onBeforeRequest?.addListener && web.onCompleted?.addListener && web.onErrorOccurred?.addListener);
89
+ const watched = new Map();
90
+ function watch(id) {
91
+ const record = { inflight: new Set(), quietSince: now() };
92
+ const begin = details => {
93
+ // A new document: the requests of the one it replaces end with it (Playwright starts counting again, too).
94
+ if (details?.type === 'main_frame') record.inflight.clear();
95
+ record.inflight.add(String(details?.requestId));
96
+ };
97
+ const end = details => { if (record.inflight.delete(String(details?.requestId)) && !record.inflight.size) record.quietSince = now(); };
98
+ const entry = { record, begin, end }, filter = { urls: ['<all_urls>'], tabId: id };
99
+ watched.set(id, entry);
100
+ try { web.onBeforeRequest.addListener(begin, filter); web.onCompleted.addListener(end, filter); web.onErrorOccurred.addListener(end, filter); }
101
+ catch { unwatch(id); }
102
+ }
103
+ function unwatch(id) {
104
+ const entry = watched.get(id); if (!entry) return;
105
+ watched.delete(id);
106
+ for (const [event, listener] of [['onBeforeRequest', entry.begin], ['onCompleted', entry.end], ['onErrorOccurred', entry.end]]) { try { web[event].removeListener(listener); } catch {} }
107
+ }
108
+ function rewatch() {
109
+ if (!watchable) return;
110
+ const held = new Set([...tabs.values()].filter(t => t.owner).map(t => t.id));
111
+ for (const id of [...watched.keys()]) if (!held.has(id)) unwatch(id);
112
+ for (const id of held) if (!watched.has(id)) watch(id);
113
+ }
114
+ const persist = async () => { rewatch(); await save({ tabs: [...tabs.values()], sites, versions: [...versions], allowNewTabs, uploads: true, downloads, fullControl, modeVersion }); changed(current()); };
55
115
  async function live(t) {
56
116
  try { const tab = await chrome.tabs.get(t.id); t.url = shownUrl(tab); t.title = clip(tab.title); return tab; }
57
117
  catch { move(t.id); tabs.delete(t.handle); moves.delete(t.id); await persist(); fail('TAB_CLOSED'); }
@@ -376,6 +436,92 @@ export function createEngine(chrome, { readUpload, save = async () => {}, change
376
436
  const after = (await chrome.tabs.query({ active: true, windowId: opened.windowId }))[0];
377
437
  if (after?.id !== t.id || after.url !== opened.url) fail('ACTIVE_TAB_REQUIRED');
378
438
  await recheck(); result.base64 = data.split(',')[1]; result.mimeType = 'image/png';
439
+ } else if (op === 'wait' && args.loadState) {
440
+ // A load-state wait reads the tab (and, for 'networkidle', the requests the watch saw); nothing is done to the
441
+ // page. 'load': the tab is not loading and has no navigation pending. 'networkidle': also no request of the tab
442
+ // in flight for `idleMs` (already so for a page that has been quiet: it answers at once). Every page the tab
443
+ // shows meanwhile must be one the mode allows. The tab closing is TAB_CLOSED; the timeout (args.timeout, or
444
+ // the deadline) is TIMEOUT.
445
+ if (args.loadState === 'networkidle' && !watchable) fail('NETWORK_IDLE_UNAVAILABLE');
446
+ const until = Math.min(now() + longBudget(op, args), expires);
447
+ for (;;) {
448
+ const reading = await live(t); guard();
449
+ if (began !== epoch || tabs.get(tab) !== t || t.owner !== owner) fail('TAB_NOT_APPROVED');
450
+ for (const url of [reading.url, reading.pendingUrl]) if (url) { await landing(url); guard(); }
451
+ let idle = reading.status !== 'loading' && !reading.pendingUrl;
452
+ if (idle && args.loadState === 'networkidle') {
453
+ rewatch();
454
+ const seen = watched.get(t.id)?.record;
455
+ if (!seen) fail('NETWORK_IDLE_UNAVAILABLE');
456
+ idle = !seen.inflight.size && now() - seen.quietSince >= idleMs;
457
+ }
458
+ if (idle) break;
459
+ if (now() >= until) fail('TIMEOUT');
460
+ await new Promise(resolve => setTimeout(resolve, Math.max(1, Math.min(pollMs, until - now()))));
461
+ }
462
+ await authorized(op, tab, owner, {}, blocked); guard(); denyControlHost(t.url);
463
+ result = { ok: true, url: t.url, title: String(t.title || '').slice(0, 1000), loadState: args.loadState };
464
+ } else if (op === 'evaluate') {
465
+ // Page JavaScript, through chrome.userScripts.execute: the one way an MV3 extension may run code it did not ship,
466
+ // and only where the owner switched "Allow User Scripts" on for this extension (USER_SCRIPTS_DISABLED says how).
467
+ // Held to every gate of a page command (the agent's own tab, a page the mode allows, never SynaBun's own, the
468
+ // approval and connection generations, the deadline), and to one document: the frame's document is read first in
469
+ // the isolated world (its id and its address, which the page cannot forge), that address passes the same rule as
470
+ // the tab's, and the script runs in that document only (gone meanwhile: nothing runs).
471
+ if (t.url === 'about:blank') fail('BLANK_PAGE');
472
+ await recheck();
473
+ const scripts = chrome.userScripts;
474
+ const available = async () => { try { await scripts.getScripts(); return true; } catch { return false; } };
475
+ if (!scripts || !await available()) fail('USER_SCRIPTS_DISABLED');
476
+ if (typeof scripts.execute !== 'function') fail('USER_SCRIPTS_UNSUPPORTED');
477
+ guard();
478
+ const frame = args.frame ?? 0;
479
+ let probe;
480
+ try { probe = await act(() => chrome.scripting.executeScript({ target: { tabId: t.id, frameIds: [frame] }, world: 'ISOLATED', injectImmediately: true, func: () => location.href })); }
481
+ catch (error) { if (error?.code) throw error; guard(); await live(t); fail(frame ? 'FRAME_NOT_FOUND' : 'OPERATION_FAILED'); }
482
+ const page = probe?.[0];
483
+ if (typeof page?.documentId !== 'string' || typeof page.result !== 'string') fail(frame ? 'FRAME_NOT_FOUND' : 'TAB_NOT_APPROVED');
484
+ await recheck();
485
+ // A frame's document is an http(s) page of its own: a blank or srcdoc frame takes the origin of whoever made it.
486
+ if (!/^https?:/i.test(page.result)) fail('RESTRICTED_PAGE');
487
+ await landing(page.result); guard();
488
+ const cap = Math.max(1, Math.min(args.maxChars || EVALUATE_RESULT_MAX, EVALUATE_RESULT_MAX));
489
+ const EXPIRED = {}; let timer, running;
490
+ try {
491
+ running = Promise.resolve(act(() => scripts.execute({ target: { tabId: t.id, documentIds: [page.documentId] }, world: args.world || 'MAIN',
492
+ injectImmediately: true, js: [{ code: pageScript(args, cap) }] })));
493
+ } catch (error) { if (error?.code) throw error; running = Promise.reject(error); }
494
+ running.catch(() => {});
495
+ // The script's own timeout, never past the command's deadline. The page's script cannot be stopped: at the
496
+ // timeout the answer is TIMEOUT and whatever it returns later is dropped.
497
+ const expired = new Promise(resolve => { timer = setTimeout(resolve, Math.max(0, Math.min(longBudget(op, args), expires - now())), EXPIRED); });
498
+ let outcome;
499
+ try { outcome = await Promise.race([running, expired]); }
500
+ catch {
501
+ // The browser refused: the document is gone (the tab navigated or closed), or user scripts were switched off.
502
+ guard(); await live(t);
503
+ if (began !== epoch || moved(t.id) !== tabBegan || !frame && t.url !== page.result) fail('TAB_NOT_APPROVED');
504
+ if (!await available()) fail('USER_SCRIPTS_DISABLED');
505
+ fail('OPERATION_FAILED');
506
+ } finally { clearTimeout(timer); }
507
+ guard();
508
+ if (outcome === EXPIRED) fail('TIMEOUT');
509
+ // The script may itself have navigated the tab: that is its effect, not a reason to withhold what it returned
510
+ // from the document that was checked. An owner's revocation meanwhile is (guard(), the epoch).
511
+ if (began !== epoch) fail('TAB_NOT_APPROVED');
512
+ if (moved(t.id) !== tabBegan) t.nav = nonce();
513
+ const entry = Array.isArray(outcome) ? outcome[0] : null, reply = entry?.result;
514
+ if (reply?.synabun === 1 && reply.ok === true && typeof reply.json === 'string') {
515
+ const value = clipped(reply.json, cap), total = Number.isSafeInteger(reply.length) && reply.length > reply.json.length ? reply.length : reply.json.length;
516
+ result = { ok: true, value, ...(value.length < total ? { truncated: true, valueLength: total } : {}) };
517
+ } else {
518
+ // What the page's script threw (the wrapper's report), or what the browser said when it could not compile or
519
+ // run it. A page error is an answer about the page, with its own code: the bridge did what it was asked.
520
+ const threw = reply?.synabun === 1 && reply.ok === false, text = (value, max) => String(value ?? '').slice(0, max);
521
+ const message = threw ? [text(reply.name, 200), text(reply.message, 2000)].filter(Boolean).join(': ')
522
+ : typeof entry?.error === 'string' && entry.error ? text(entry.error, 2000) : 'The script returned no result: it did not compile, or the page stopped it.';
523
+ result = { ok: false, code: 'PAGE_ERROR', error: `PAGE_ERROR: ${ERROR_TEXT.PAGE_ERROR}`, errorMessage: message || 'The script threw.', errorStack: threw ? text(reply.stack, 6000) : '' };
524
+ }
379
525
  } else if (fullControl && t.url === 'about:blank') {
380
526
  // A blank tab (where a new agent tab starts) has no page an extension may script: it reads as empty, a plain
381
527
  // wait waits, and anything that needs an element finds none.
@@ -403,14 +549,18 @@ export function createEngine(chrome, { readUpload, save = async () => {}, change
403
549
  const documentId = injection?.[0]?.documentId;
404
550
  if (!documentId) fail('TAB_NOT_APPROVED');
405
551
  delivery = { documentId };
406
- const sizes = [];
552
+ const metadata = [];
407
553
  let remaining = MAX_FILE;
408
554
  for (let index = 0; index < args.files.length; index++) {
409
555
  await recheck();
410
- const blob = await readUpload(input.id, index, Math.max(1, expires - now()));
556
+ const response = await readUpload(input.id, index, Math.max(1, expires - now()));
557
+ const timestamp = response.headers.get('X-SynaBun-Last-Modified');
558
+ if (!timestamp || !Number.isSafeInteger(Number(timestamp))) fail('UPLOAD_METADATA_UNAVAILABLE');
559
+ const blob = await response.blob();
560
+ if (!blob.type) fail('UPLOAD_METADATA_UNAVAILABLE');
411
561
  if (blob.size > remaining) fail('UPLOAD_TOO_LARGE');
412
562
  remaining -= blob.size;
413
- sizes.push(blob.size);
563
+ metadata.push({ size: blob.size, type: blob.type, lastModified: Number(timestamp) });
414
564
  // Chrome serializes tab messages as JSON. Keep even a 50 MB file below its IPC cap.
415
565
  const chunkSize = 1024 * 1024;
416
566
  for (let pos = 0; pos < blob.size; pos += chunkSize) {
@@ -427,7 +577,7 @@ export function createEngine(chrome, { readUpload, save = async () => {}, change
427
577
  }
428
578
  }
429
579
  await recheck();
430
- pageArgs = { ...args, uploadId: input.id, sizes };
580
+ pageArgs = { ...args, uploadId: input.id, metadata };
431
581
  }
432
582
  result = await act(() => chrome.tabs.sendMessage(t.id, { kind: 'synabun-fixed-command', op, args: pageArgs,
433
583
  sites: fullControl ? null : sites.filter(site => !blockedHosts.includes(new URL(site).hostname)), blocked, downloads, nav: t.nav,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "SynaBun Browser Bridge",
4
- "version": "1.3.0",
4
+ "version": "1.4.0",
5
5
  "minimum_chrome_version": "120",
6
6
  "description": "Lets SynaBun agents use your everyday browser: every site and tab (full control), or only what you share.",
7
7
  "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsDPDDuBTQq9nQgulmTSvzujxyOMZ7A7ttMSXtbIwup/X3kOlbkqoJEqQRGGJeb7+cNBSiiDBA5lhS0oYc9YeFcwNCucNMvGawDGblbQzDWEmn9dDK1krFVXWqNHVPIrEWlzCD2swXmIE2FCjMd5zw6dSRmmxu7VgE6bzvuOgB/W/oeOAyCsEDhDRDLBkjmb+yCsuexiXRWoempPsvAVhxhE8zEQJ1e8ChlFMtpOXSobU+YDgKYfcFy9Fbmk/o6M6B9y5zSlzs/HYIu7xvcCwjZI457idVMRxxAT6J/kXytmfKe/zbi5IO5/i0x9SCA1HRvt8K3nJqoH03h4TOvFwOwIDAQAB",
@@ -9,6 +9,8 @@
9
9
  "storage",
10
10
  "alarms",
11
11
  "scripting",
12
+ "userScripts",
13
+ "webRequest",
12
14
  "tabs",
13
15
  "activeTab"
14
16
  ],
@@ -18,6 +18,38 @@ export function localDeadline(receivedAt, deadline) { return receivedAt + deadli
18
18
  // The watchdog for a browser call that never returns: once a command runs, the queue waits at most this long for it.
19
19
  // It never gives a command more time than its deadline; the effective limit is the earlier of the two.
20
20
  export const QUEUE_LIMIT = 30000;
21
+ // ── Long operations (1.4.0): running page JavaScript (`evaluate`) and a load-state wait (`wait` with `loadState`) ──
22
+ // They may take longer than COMMAND_WAIT, so they carry a longer deadline (up to LONG_WAIT) and never hold the worker's
23
+ // queue: the extension runs them beside the ordinary commands, each under its own deadline. The server waits
24
+ // commandWait(op, args) for one: the operation's own timeout plus LONG_MARGIN, never less than COMMAND_WAIT.
25
+ export const LONG_WAIT = 65000;
26
+ export const LONG_MARGIN = 5000;
27
+ // evaluate: the script's own timeout (args.timeout; default, most), the script source and its JSON arguments (characters),
28
+ // and the JSON text of its result (characters; a longer one is cut and flagged `truncated`).
29
+ export const EVALUATE_TIMEOUT = 30000;
30
+ export const EVALUATE_TIMEOUT_MAX = 60000;
31
+ export const EVALUATE_SCRIPT_MAX = 500000;
32
+ export const EVALUATE_PARAMS_MAX = 100000;
33
+ export const EVALUATE_RESULT_MAX = 1000000;
34
+ // 'MAIN' is the page's own JavaScript world (its globals are visible); 'USER_SCRIPT' is Chrome's separate world for
35
+ // user scripts (the DOM, none of the page's globals, exempt from the page's CSP).
36
+ export const EVALUATE_WORLDS = ['MAIN', 'USER_SCRIPT'];
37
+ // wait with loadState: 'load' (the tab finished loading) or 'networkidle' (also no request of the tab in flight for
38
+ // NETWORK_IDLE_QUIET ms, as Playwright counts it), within args.timeout (default, most).
39
+ export const LOAD_STATES = ['load', 'networkidle'];
40
+ export const NETWORK_IDLE_QUIET = 500;
41
+ export const NETWORK_IDLE_TIMEOUT = 15000;
42
+ export const NETWORK_IDLE_TIMEOUT_MAX = 60000;
43
+ export function longOp(op, args) { return op === 'evaluate' || op === 'wait' && args?.loadState !== undefined; }
44
+ // The operation's own time limit (ms), from args.timeout: its default when none is given, never above its most.
45
+ export function longBudget(op, args = {}) {
46
+ const [normal, most] = op === 'evaluate' ? [EVALUATE_TIMEOUT, EVALUATE_TIMEOUT_MAX] : [NETWORK_IDLE_TIMEOUT, NETWORK_IDLE_TIMEOUT_MAX];
47
+ return Math.max(1, Math.min(Number.isSafeInteger(args?.timeout) ? args.timeout : normal, most));
48
+ }
49
+ // How long the server waits for the answer to a command, and the most its `deadline` may say.
50
+ export function commandWait(op, args = {}) {
51
+ return longOp(op, args) ? Math.max(COMMAND_WAIT, Math.min(LONG_WAIT, longBudget(op, args) + LONG_MARGIN)) : COMMAND_WAIT;
52
+ }
21
53
  export function fail(code, message = code) { throw Object.assign(new Error(message), { code }); }
22
54
  export function object(value, keys) {
23
55
  if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).some(k => !keys.includes(k))) fail('INVALID_MESSAGE');
@@ -131,7 +163,10 @@ export function inventory(value) {
131
163
  }
132
164
  return value;
133
165
  }
134
- export const COMMANDS = ['create', 'claim', 'release', 'navigate', 'back', 'forward', 'reload', 'snapshot', 'click', 'hover', 'fill', 'type', 'press', 'select', 'scroll', 'wait', 'content', 'screenshot', 'upload', 'download', 'revokeTab', 'revokeSite', 'disconnect', 'revoke', 'mode', 'reset'];
166
+ export const COMMANDS = ['create', 'claim', 'release', 'navigate', 'back', 'forward', 'reload', 'snapshot', 'click', 'hover', 'fill', 'type', 'press', 'select', 'scroll', 'wait', 'content', 'screenshot', 'upload', 'download', 'evaluate', 'revokeTab', 'revokeSite', 'disconnect', 'revoke', 'mode', 'reset'];
167
+ // The first extension version that knows `evaluate` and `wait` with `loadState`. An older one ends the connection on a
168
+ // command it does not know, so the server never sends it one (it answers EXTENSION_RELOAD_REQUIRED itself).
169
+ export const LONG_OPS_SINCE = '1.4.0';
135
170
  export const HISTORY = ['back', 'forward'];
136
171
  // The owner's control messages: revocations, the mode (full control or restricted) and `reset` (a restarted server
137
172
  // hands back every tab agents of its previous process held). They overtake queued commands on both sides, are never
@@ -142,17 +177,24 @@ export function command(value) {
142
177
  if (value.type !== 'command' || !COMMANDS.includes(value.op)) fail('UNSUPPORTED_IN_EXTENSION_MODE');
143
178
  handle(value.id); if (value.tab !== null) handle(value.tab); handle(value.owner);
144
179
  // Required on every command: whole milliseconds, 1 to COMMAND_WAIT (the server never has more left than its wait).
145
- if (!Number.isSafeInteger(value.deadline) || value.deadline < 1 || value.deadline > COMMAND_WAIT) fail('INVALID_MESSAGE');
180
+ // A long operation's may reach commandWait(op, args): checked below, once its arguments are known to be an object.
181
+ if (!Number.isSafeInteger(value.deadline) || value.deadline < 1 || value.deadline > LONG_WAIT) fail('INVALID_MESSAGE');
146
182
  // SynaBun's own addresses, which no command may reach (controlSurface): its public aliases (any port), its ports,
147
183
  // and this computer's names and interface addresses.
148
184
  for (const key of ['blockedHosts', 'selfHosts']) {
149
185
  if (value[key] !== undefined && (!Array.isArray(value[key]) || value[key].length > 200 || value[key].some(h => typeof h !== 'string' || h.length > 253 || !/^[a-zA-Z0-9.:%-]+$/.test(h)))) fail('INVALID_MESSAGE');
150
186
  }
151
187
  if (value.blockedPorts !== undefined && (!Array.isArray(value.blockedPorts) || value.blockedPorts.length > 32 || value.blockedPorts.some(p => !Number.isSafeInteger(p) || p < 1 || p > 65535))) fail('INVALID_MESSAGE');
152
- const a = value.args; object(a, ['url', 'ref', 'selector', 'nthMatch', 'value', 'text', 'key', 'direction', 'distance', 'maxChars', 'offset', 'timeout', 'state', 'files', 'site', 'fullControl', 'version']);
188
+ const a = value.args; object(a, ['url', 'ref', 'selector', 'nthMatch', 'value', 'text', 'key', 'direction', 'distance', 'maxChars', 'offset', 'timeout', 'state', 'files', 'site', 'fullControl', 'version',
189
+ 'expression', 'body', 'params', 'world', 'frame', 'loadState']);
190
+ if (value.deadline > commandWait(value.op, a)) fail('INVALID_MESSAGE');
153
191
  for (const [k, v] of Object.entries(a)) {
154
192
  if (k === 'fullControl') { if (typeof v !== 'boolean') fail('INVALID_MESSAGE'); }
155
193
  else if (k === 'version') { if (!Number.isSafeInteger(v) || v < 0) fail('INVALID_MESSAGE'); }
194
+ // A frame of the tab, by Chrome's frame id (0, the default, is the top document).
195
+ else if (k === 'frame') { if (!Number.isSafeInteger(v) || v < 0 || v > 2147483647) fail('INVALID_MESSAGE'); }
196
+ else if (k === 'expression' || k === 'body') string(v, EVALUATE_SCRIPT_MAX);
197
+ else if (k === 'params') string(v, EVALUATE_PARAMS_MAX);
156
198
  else if (['nthMatch', 'distance', 'maxChars', 'offset', 'timeout'].includes(k)) {
157
199
  if (!Number.isSafeInteger(v) || v < 0 || v > 1000000) fail('INVALID_MESSAGE');
158
200
  } else if (k === 'files') {
@@ -175,18 +217,50 @@ export function command(value) {
175
217
  if (HISTORY.includes(value.op) && (value.tab === null || Object.keys(a).length)) fail('INVALID_MESSAGE');
176
218
  if (a.direction !== undefined && !['up', 'down', 'left', 'right'].includes(a.direction)) fail('INVALID_MESSAGE');
177
219
  if (a.state !== undefined && !['visible', 'hidden', 'attached', 'detached'].includes(a.state)) fail('INVALID_MESSAGE');
220
+ // evaluate: exactly one of `expression` (one JavaScript expression; a function it evaluates to is called with the
221
+ // arguments) and `body` (the body of an async function whose parameter `args` is the array of arguments), with
222
+ // `params` (the arguments: the JSON text of an array), `world`, `frame`, `timeout` and `maxChars`, and nothing else.
223
+ const evaluate = ['expression', 'body', 'params', 'world', 'frame'];
224
+ if (value.op === 'evaluate') {
225
+ if (value.tab === null || (typeof a.expression === 'string') === (typeof a.body === 'string') || !(a.expression ?? a.body).trim()) fail('INVALID_MESSAGE');
226
+ if (Object.keys(a).some(k => !evaluate.includes(k) && k !== 'timeout' && k !== 'maxChars')) fail('INVALID_MESSAGE');
227
+ if (a.world !== undefined && !EVALUATE_WORLDS.includes(a.world)) fail('INVALID_MESSAGE');
228
+ if (a.params !== undefined) {
229
+ let list; try { list = JSON.parse(a.params); } catch { list = null; }
230
+ if (!Array.isArray(list)) fail('INVALID_MESSAGE');
231
+ }
232
+ } else if (evaluate.some(k => a[k] !== undefined)) fail('INVALID_MESSAGE');
233
+ // A load-state wait names the state and, at most, its timeout: it waits for the tab, not for an element.
234
+ if (a.loadState !== undefined && (value.op !== 'wait' || value.tab === null || !LOAD_STATES.includes(a.loadState)
235
+ || Object.keys(a).some(k => k !== 'loadState' && k !== 'timeout'))) fail('INVALID_MESSAGE');
178
236
  return value;
179
237
  }
180
238
  export function payload(value) {
181
239
  if (value?.type === 'state') { object(value, ['type', 'inventory']); inventory(value.inventory); }
182
240
  else if (value?.type === 'result') {
183
241
  object(value, ['type', 'id', 'result', 'inventory']); handle(value.id); inventory(value.inventory);
184
- object(value.result, ['ok', 'code', 'error', 'url', 'title', 'snapshotText', 'mode', 'snapshotId', 'content', 'text', 'base64', 'mimeType', 'tab', 'downloadId']);
242
+ // evaluate adds `value` (the JSON text of the script's result), `truncated` with `valueLength` (the result was
243
+ // longer than its cap: `value` is then the beginning of that JSON text, not valid JSON) and, with code PAGE_ERROR,
244
+ // `errorMessage` and `errorStack` (what the page's script threw). A load-state wait adds `loadState`.
245
+ object(value.result, ['ok', 'code', 'error', 'url', 'title', 'snapshotText', 'mode', 'snapshotId', 'content', 'text', 'base64', 'mimeType', 'tab', 'downloadId', 'files',
246
+ 'value', 'truncated', 'valueLength', 'errorMessage', 'errorStack', 'loadState']);
185
247
  if (typeof value.result.ok !== 'boolean') fail('INVALID_MESSAGE');
186
248
  for (const [k, v] of Object.entries(value.result)) {
187
249
  if (k === 'ok') continue;
188
- if (k === 'downloadId') { if (!Number.isSafeInteger(v)) fail('INVALID_MESSAGE'); }
189
- else string(v, k === 'base64' ? MAX_MESSAGE - 4096 : ['content', 'text', 'snapshotText'].includes(k) ? 1000000 : 8192);
250
+ if (k === 'files') {
251
+ if (!Array.isArray(v) || !v.length || v.length > 4) fail('INVALID_MESSAGE');
252
+ let total = 0;
253
+ for (const file of v) {
254
+ object(file, ['name', 'type', 'size']);
255
+ if (!string(file.name, 255) || /[\\/]/.test(file.name) || !string(file.type, 255)) fail('INVALID_MESSAGE');
256
+ if (!Number.isSafeInteger(file.size) || file.size < 0) fail('INVALID_MESSAGE');
257
+ total += file.size;
258
+ }
259
+ if (total > MAX_FILE) fail('INVALID_MESSAGE');
260
+ } else if (k === 'downloadId') { if (!Number.isSafeInteger(v)) fail('INVALID_MESSAGE'); }
261
+ else if (k === 'valueLength') { if (!Number.isSafeInteger(v) || v < 0) fail('INVALID_MESSAGE'); }
262
+ else if (k === 'truncated') { if (typeof v !== 'boolean') fail('INVALID_MESSAGE'); }
263
+ else string(v, k === 'base64' ? MAX_MESSAGE - 4096 : ['content', 'text', 'snapshotText', 'value'].includes(k) ? EVALUATE_RESULT_MAX : 8192);
190
264
  }
191
265
  } else if (value?.type === 'ping' || value?.type === 'pong' || value?.type === 'unpair') object(value, ['type']);
192
266
  // The server gave up on a command (its wait ended): the extension stops it, queued or running, and never starts it.
@@ -222,9 +296,20 @@ export const ERROR_TEXT = Object.freeze({
222
296
  UPLOAD_TOO_LARGE: 'The selected files exceed the 50 MB total upload limit.',
223
297
  UPLOAD_FILE_REFUSED: 'Choose readable regular files inside the extension upload folder shown in Settings → Browser.',
224
298
  UPLOAD_MULTIPLE: 'This file input accepts only one file.',
299
+ UPLOAD_DISABLED: 'The file input is disabled.',
300
+ UPLOAD_ACCEPT_MISMATCH: 'The file input’s accept filter excludes one or more selected files. Check the accepted MIME types or filename extensions.',
301
+ UPLOAD_ASSIGNMENT_FAILED: 'The file input did not receive the expected names, types and sizes.',
302
+ UPLOAD_METADATA_UNAVAILABLE: 'Restart SynaBun and reload SynaBun Browser Bridge to enable file metadata.',
225
303
  PERMISSION_REQUIRED: 'Enable this feature in the extension popup first (downloads; in restricted mode also agent-created tabs).', OPERATION_FAILED: 'The browser refused this operation.',
226
304
  TIMEOUT: 'The operation timed out. Its outcome may be uncertain; observe before retrying.',
227
305
  CANCELLED: 'An approval was revoked or the connection ended while this command was pending. It was stopped before its next browser action; one already under way may have happened, so observe before retrying.',
306
+ USER_SCRIPTS_DISABLED: 'Running page JavaScript is switched off for the SynaBun extension in this browser. The owner switches it on once: open chrome://extensions (edge://extensions in Edge), choose Details on "SynaBun Browser Bridge", turn on "Allow User Scripts" (Chrome or Edge 138 and later; on an older version turn on Developer mode at the top of that page instead), then press Reload on the extension. Nothing was run.',
307
+ USER_SCRIPTS_UNSUPPORTED: 'This browser cannot run page JavaScript for an extension (chrome.userScripts.execute needs Chrome or Edge 135 or later). Update the browser. Nothing was run.',
308
+ EXTENSION_RELOAD_REQUIRED: 'The paired browser still runs an older SynaBun Browser Bridge than this operation needs. The owner reloads it on the browser’s extensions page (chrome://extensions → SynaBun Browser Bridge → Reload). Nothing was done.',
309
+ PAGE_ERROR: 'The page’s script threw, or did not compile (evaluate takes one expression: wrap statements in a function, (() => { …; return value; })()). errorMessage and errorStack say what the page reported; the bridge itself did not fail.',
310
+ BLANK_PAGE: 'The tab shows the blank start page, where no script can run. Navigate it to an http(s) page first.',
311
+ FRAME_NOT_FOUND: 'The tab has no frame with this id that a script can run in (frame 0 is the top document). Nothing was run.',
312
+ NETWORK_IDLE_UNAVAILABLE: 'The extension cannot watch this browser’s network requests (its webRequest permission is not in effect). The owner reloads SynaBun Browser Bridge on the browser’s extensions page; until then wait for a selector or a fixed time instead.',
228
313
  });
229
314
  export function safeError(error) {
230
315
  const code = Object.hasOwn(ERROR_TEXT, error?.code) ? error.code : 'OPERATION_FAILED';
@@ -1,4 +1,4 @@
1
- import { channel, command, CONTROL, equalMac, fail, hostPattern, localDeadline, mac, nonce, object, pairingKey, parse, payload, QUEUE_LIMIT, reserve, safeError } from './protocol.js';
1
+ import { channel, command, CONTROL, equalMac, fail, hostPattern, localDeadline, longOp, mac, nonce, object, pairingKey, parse, payload, QUEUE_LIMIT, reserve, safeError } from './protocol.js';
2
2
  import { createEngine } from './engine.js';
3
3
  import { badgeFor } from './popup-view.js';
4
4
  import { popupLocale, translator } from './popup-strings.js';
@@ -31,7 +31,7 @@ const engine = createEngine(chrome, {
31
31
  credentials: 'omit', cache: 'no-store', signal: AbortSignal.timeout(Math.ceil(timeout)),
32
32
  });
33
33
  if (!response.ok) fail(response.status === 400 ? await response.text() : 'CANCELLED');
34
- return response.blob();
34
+ return response;
35
35
  },
36
36
  save: async value => {
37
37
  const { tabs, ...prefs } = value;
@@ -91,7 +91,12 @@ const commands = new Map();
91
91
  // and so is one whose turn comes later than `held.startBy` (one margin before its deadline). Once it starts, the timer
92
92
  // is re-armed for the earlier of the deadline and QUEUE_LIMIT, the watchdog for a browser call that never returns;
93
93
  // either way the queue moves on to the next command at once. The server's cancel calls the same `expire`.
94
+ // A long operation (protocol.js longOp: evaluate, a load-state wait) may run for a minute, far past the deadline of
95
+ // any command behind it, so it never takes a turn in the queue: it starts at once, beside the queue, under its own
96
+ // deadline alone (no QUEUE_LIMIT; its own timeout is its watchdog). One agent's slow script or a page that never
97
+ // goes idle therefore holds up nobody else's tab. The engine holds it to the same ticket and gates as any command.
94
98
  function enqueue(ws, message, held) {
99
+ const long = longOp(message.op, message.args);
95
100
  let timer, started = false, expire;
96
101
  const limit = new Promise((_resolve, reject) => { expire = () => { held.stopped = true; reject(coded('TIMEOUT')); }; });
97
102
  limit.catch(() => { if (!started) void answer(ws, message, limit).catch(() => {}); });
@@ -100,12 +105,15 @@ function enqueue(ws, message, held) {
100
105
  const done = () => { clearTimeout(timer); if (commands.get(message.id) === expire) commands.delete(message.id); };
101
106
  commands.set(message.id, expire);
102
107
  arm(held.expires - engine.now());
103
- work = work.catch(() => {}).then(() => {
108
+ const run = () => {
104
109
  if (!held.stopped && engine.now() >= held.startBy) expire();
105
110
  if (held.stopped) { done(); return; }
106
- started = true; arm(Math.min(QUEUE_LIMIT, held.expires - engine.now()));
111
+ started = true; arm(long ? held.expires - engine.now() : Math.min(QUEUE_LIMIT, held.expires - engine.now()));
107
112
  return answer(ws, message, Promise.race([engine.execute(message, held), limit]).finally(done));
108
- }).catch(() => {}); // A command failure is an answer, never a transport revocation.
113
+ };
114
+ // A command failure is an answer, never a transport revocation.
115
+ if (long) void Promise.resolve().then(run).catch(() => {});
116
+ else work = work.catch(() => {}).then(run).catch(() => {});
109
117
  }
110
118
  function schedule() {
111
119
  clearTimeout(reconnectTimer);
@@ -1,4 +1,4 @@
1
- /* SynaBun Style Guide rev 19: design tokens. Generated, do not edit by hand. */
1
+ /* SynaBun Style Guide rev 22: design tokens. Generated, do not edit by hand. */
2
2
  :root {
3
3
  color-scheme: dark;
4
4
  --color-primary-50: #cccccc;