synabun 2.4.1 → 2.4.3

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 (345) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +1 -1
  3. package/docs/browser-extension-bridge.md +46 -6
  4. package/lib/data-home-files.js +4 -2
  5. package/lib/first-launch-protection.js +8 -2
  6. package/lib/release-npm-ci.mjs +23 -1
  7. package/lib/update-snapshot.js +11 -4
  8. package/mcp-server/dist/http.d.ts.map +1 -1
  9. package/mcp-server/dist/http.js +25 -2
  10. package/mcp-server/dist/http.js.map +1 -1
  11. package/mcp-server/dist/index.d.ts.map +1 -1
  12. package/mcp-server/dist/index.js +62 -17
  13. package/mcp-server/dist/index.js.map +1 -1
  14. package/mcp-server/dist/services/browser-bench.d.ts +22 -22
  15. package/mcp-server/dist/services/memory-maintenance.d.ts +1 -0
  16. package/mcp-server/dist/services/memory-maintenance.d.ts.map +1 -1
  17. package/mcp-server/dist/services/memory-maintenance.js +34 -45
  18. package/mcp-server/dist/services/memory-maintenance.js.map +1 -1
  19. package/mcp-server/dist/services/memory-migration-copy.d.ts +144 -0
  20. package/mcp-server/dist/services/memory-migration-copy.d.ts.map +1 -0
  21. package/mcp-server/dist/services/memory-migration-copy.js +467 -0
  22. package/mcp-server/dist/services/memory-migration-copy.js.map +1 -0
  23. package/mcp-server/dist/services/memory-migration-worker.d.ts +2 -0
  24. package/mcp-server/dist/services/memory-migration-worker.d.ts.map +1 -0
  25. package/mcp-server/dist/services/memory-migration-worker.js +60 -0
  26. package/mcp-server/dist/services/memory-migration-worker.js.map +1 -0
  27. package/mcp-server/dist/services/memory-retrieval.d.ts +4 -0
  28. package/mcp-server/dist/services/memory-retrieval.d.ts.map +1 -1
  29. package/mcp-server/dist/services/memory-retrieval.js +188 -40
  30. package/mcp-server/dist/services/memory-retrieval.js.map +1 -1
  31. package/mcp-server/dist/services/memory-schema.d.ts +58 -2
  32. package/mcp-server/dist/services/memory-schema.d.ts.map +1 -1
  33. package/mcp-server/dist/services/memory-schema.js +190 -13
  34. package/mcp-server/dist/services/memory-schema.js.map +1 -1
  35. package/mcp-server/dist/services/memory-sessions.d.ts +19 -1
  36. package/mcp-server/dist/services/memory-sessions.d.ts.map +1 -1
  37. package/mcp-server/dist/services/memory-sessions.js +56 -20
  38. package/mcp-server/dist/services/memory-sessions.js.map +1 -1
  39. package/mcp-server/dist/services/memory-verification.d.ts.map +1 -1
  40. package/mcp-server/dist/services/memory-verification.js +8 -5
  41. package/mcp-server/dist/services/memory-verification.js.map +1 -1
  42. package/mcp-server/dist/services/neural-interface.d.ts +5 -0
  43. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  44. package/mcp-server/dist/services/neural-interface.js +19 -2
  45. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  46. package/mcp-server/dist/services/retrieval-reader-worker.d.ts +2 -0
  47. package/mcp-server/dist/services/retrieval-reader-worker.d.ts.map +1 -0
  48. package/mcp-server/dist/services/retrieval-reader-worker.js +76 -0
  49. package/mcp-server/dist/services/retrieval-reader-worker.js.map +1 -0
  50. package/mcp-server/dist/services/retrieval-reader.d.ts +38 -0
  51. package/mcp-server/dist/services/retrieval-reader.d.ts.map +1 -0
  52. package/mcp-server/dist/services/retrieval-reader.js +145 -0
  53. package/mcp-server/dist/services/retrieval-reader.js.map +1 -0
  54. package/mcp-server/dist/services/sqlite-write.d.ts +14 -0
  55. package/mcp-server/dist/services/sqlite-write.d.ts.map +1 -0
  56. package/mcp-server/dist/services/sqlite-write.js +94 -0
  57. package/mcp-server/dist/services/sqlite-write.js.map +1 -0
  58. package/mcp-server/dist/services/sqlite.d.ts +39 -0
  59. package/mcp-server/dist/services/sqlite.d.ts.map +1 -1
  60. package/mcp-server/dist/services/sqlite.js +249 -8
  61. package/mcp-server/dist/services/sqlite.js.map +1 -1
  62. package/mcp-server/dist/services/tool-catalog.d.ts +1 -1
  63. package/mcp-server/dist/services/typesafe-config.d.ts +7 -1
  64. package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
  65. package/mcp-server/dist/services/typesafe-config.js +32 -10
  66. package/mcp-server/dist/services/typesafe-config.js.map +1 -1
  67. package/mcp-server/dist/services/typesafe.d.ts.map +1 -1
  68. package/mcp-server/dist/services/typesafe.js +9 -7
  69. package/mcp-server/dist/services/typesafe.js.map +1 -1
  70. package/mcp-server/dist/services/vector-cache.d.ts +32 -0
  71. package/mcp-server/dist/services/vector-cache.d.ts.map +1 -1
  72. package/mcp-server/dist/services/vector-cache.js +161 -8
  73. package/mcp-server/dist/services/vector-cache.js.map +1 -1
  74. package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
  75. package/mcp-server/dist/tools/agents.d.ts +11 -7
  76. package/mcp-server/dist/tools/agents.d.ts.map +1 -1
  77. package/mcp-server/dist/tools/agents.js +27 -9
  78. package/mcp-server/dist/tools/agents.js.map +1 -1
  79. package/mcp-server/dist/tools/browser-advanced.d.ts +1 -1
  80. package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
  81. package/mcp-server/dist/tools/browser-advanced.js +10 -3
  82. package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
  83. package/mcp-server/dist/tools/browser-extension-setup.d.ts +5 -0
  84. package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -0
  85. package/mcp-server/dist/tools/browser-extension-setup.js +29 -0
  86. package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -0
  87. package/mcp-server/dist/tools/browser-interact.d.ts.map +1 -1
  88. package/mcp-server/dist/tools/browser-interact.js +6 -1
  89. package/mcp-server/dist/tools/browser-interact.js.map +1 -1
  90. package/mcp-server/dist/tools/fb-groups.d.ts +2 -2
  91. package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
  92. package/mcp-server/dist/tools/tool-groups.d.ts +1 -1
  93. package/mcp-server/package-lock.json +5 -5
  94. package/mcp-server/package.json +1 -1
  95. package/mcp-server/src/http.ts +20 -2
  96. package/mcp-server/src/index.ts +59 -17
  97. package/mcp-server/src/services/memory-maintenance.ts +31 -28
  98. package/mcp-server/src/services/memory-migration-copy.ts +419 -0
  99. package/mcp-server/src/services/memory-migration-worker.ts +55 -0
  100. package/mcp-server/src/services/memory-retrieval.ts +173 -32
  101. package/mcp-server/src/services/memory-schema.ts +194 -12
  102. package/mcp-server/src/services/memory-sessions.ts +54 -21
  103. package/mcp-server/src/services/memory-verification.ts +7 -4
  104. package/mcp-server/src/services/neural-interface.ts +22 -2
  105. package/mcp-server/src/services/retrieval-reader-worker.ts +67 -0
  106. package/mcp-server/src/services/retrieval-reader.ts +131 -0
  107. package/mcp-server/src/services/sqlite-write.ts +60 -0
  108. package/mcp-server/src/services/sqlite.ts +246 -8
  109. package/mcp-server/src/services/typesafe-config.ts +25 -6
  110. package/mcp-server/src/services/typesafe.ts +9 -7
  111. package/mcp-server/src/services/vector-cache.ts +154 -9
  112. package/mcp-server/src/tools/agents.ts +26 -9
  113. package/mcp-server/src/tools/browser-advanced.ts +10 -3
  114. package/mcp-server/src/tools/browser-extension-setup.ts +36 -0
  115. package/mcp-server/src/tools/browser-interact.ts +5 -1
  116. package/neural-interface/i18n/en.json +313 -2
  117. package/neural-interface/i18n/pt-BR.json +321 -10
  118. package/neural-interface/lib/agents/split.js +32 -4
  119. package/neural-interface/lib/assistant-api.js +52 -8
  120. package/neural-interface/lib/assistant-brains/claude.js +2 -0
  121. package/neural-interface/lib/assistant-brains/opencode.js +121 -7
  122. package/neural-interface/lib/assistant-catalog.js +2 -2
  123. package/neural-interface/lib/assistant-config.js +0 -7
  124. package/neural-interface/lib/assistant-dispatch.js +281 -95
  125. package/neural-interface/lib/assistant-envelope.js +40 -0
  126. package/neural-interface/lib/assistant-persona.js +16 -4
  127. package/neural-interface/lib/assistant-pricing.js +65 -14
  128. package/neural-interface/lib/assistant-router.js +131 -47
  129. package/neural-interface/lib/assistant-run-wait.js +45 -28
  130. package/neural-interface/lib/assistant-runtime.js +133 -42
  131. package/neural-interface/lib/backup-contents.js +158 -0
  132. package/neural-interface/lib/backup-crypto-io.js +330 -0
  133. package/neural-interface/lib/backup-crypto-worker.js +130 -0
  134. package/neural-interface/lib/backup-crypto.js +525 -0
  135. package/neural-interface/lib/backup-download.js +268 -0
  136. package/neural-interface/lib/backup-encryption.js +318 -0
  137. package/neural-interface/lib/backup-groups.js +287 -0
  138. package/neural-interface/lib/backup-restore-session.js +176 -0
  139. package/neural-interface/lib/backup-restore-stage.js +60 -0
  140. package/neural-interface/lib/backup-service.js +788 -233
  141. package/neural-interface/lib/backup-zip-reader.js +30 -18
  142. package/neural-interface/lib/backup-zip-writer.js +34 -10
  143. package/neural-interface/lib/browser-extension-adapter.js +89 -15
  144. package/neural-interface/lib/browser-extension-archive.js +149 -0
  145. package/neural-interface/lib/browser-extension-bridge.js +24 -10
  146. package/neural-interface/lib/browser-extension-folder.js +596 -76
  147. package/neural-interface/lib/browser-extension-package.js +200 -0
  148. package/neural-interface/lib/browser-extension-pin.js +84 -0
  149. package/neural-interface/lib/browser-extension-pin.json +33 -0
  150. package/{browser-extension/protocol.js → neural-interface/lib/browser-extension-protocol.js} +91 -6
  151. package/neural-interface/lib/browser-extension-setup.js +105 -18
  152. package/neural-interface/lib/claude-agent-bridge.js +1 -0
  153. package/neural-interface/lib/claude-session-cleanup.js +5 -1
  154. package/neural-interface/lib/cli-install.js +23 -3
  155. package/neural-interface/lib/cli-update-planner.js +171 -9
  156. package/neural-interface/lib/client-diagnostics.js +42 -0
  157. package/neural-interface/lib/confined-fs.js +7 -2
  158. package/neural-interface/lib/coordination/README.md +8 -2
  159. package/neural-interface/lib/coordination/contract.js +161 -0
  160. package/neural-interface/lib/coordination/database.js +999 -0
  161. package/neural-interface/lib/coordination/operations.js +436 -0
  162. package/neural-interface/lib/coordination/service.js +68 -537
  163. package/neural-interface/lib/coordination/storage-worker.js +101 -0
  164. package/neural-interface/lib/coordination/store.js +219 -1111
  165. package/neural-interface/lib/db.js +70 -32
  166. package/neural-interface/lib/health-count.js +37 -0
  167. package/neural-interface/lib/loop-stall.js +139 -0
  168. package/neural-interface/lib/maritaca/client.js +2 -2
  169. package/neural-interface/lib/maritaca/models.js +12 -17
  170. package/neural-interface/lib/maritaca/opencode.js +4 -2
  171. package/neural-interface/lib/memory-api.js +9 -1
  172. package/neural-interface/lib/memory-session-capture.js +42 -10
  173. package/neural-interface/lib/memory-store-gate.js +313 -0
  174. package/neural-interface/lib/memory-store-migrate.js +65 -0
  175. package/neural-interface/lib/memory-timers.js +7 -7
  176. package/neural-interface/lib/native-loop-providers.js +23 -17
  177. package/neural-interface/lib/native-loop-runtime.js +48 -9
  178. package/neural-interface/lib/opencode-build-preflight.js +18 -1
  179. package/neural-interface/lib/opencode-native-boundary.js +69 -8
  180. package/neural-interface/lib/opencode-provider-view.js +14 -3
  181. package/neural-interface/lib/opencode-shell-read.js +107 -0
  182. package/neural-interface/lib/opencode-stop-failures.js +40 -0
  183. package/neural-interface/lib/opencode-turn-release.js +173 -0
  184. package/neural-interface/lib/opencode-v2-client.js +4 -1
  185. package/neural-interface/lib/opencode-v2-ws-requests.js +65 -1
  186. package/neural-interface/lib/opencode2-client.js +343 -7
  187. package/neural-interface/lib/opencode2-translate.js +161 -4
  188. package/neural-interface/lib/recall-impact.js +122 -0
  189. package/neural-interface/lib/scratch-evidence.js +420 -0
  190. package/neural-interface/lib/scratch-process-guard.js +139 -0
  191. package/neural-interface/lib/scratch-references.js +279 -0
  192. package/neural-interface/lib/scratch-retention-core.js +385 -0
  193. package/neural-interface/lib/scratch-retention-worker.js +37 -0
  194. package/neural-interface/lib/scratch-retention.js +151 -0
  195. package/neural-interface/lib/session-cache-builder.js +31 -43
  196. package/neural-interface/lib/session-cache-worker.js +157 -0
  197. package/neural-interface/lib/session-indexer.js +28 -21
  198. package/neural-interface/lib/session-search-index.js +85 -0
  199. package/neural-interface/lib/skills/creation.js +1 -1
  200. package/neural-interface/lib/sqlite-integrity-worker.js +3 -1
  201. package/neural-interface/lib/style-guide/store.js +43 -3
  202. package/neural-interface/lib/system-restore.js +50 -0
  203. package/neural-interface/lib/teams/api.js +15 -6
  204. package/neural-interface/lib/teams/claims.js +67 -31
  205. package/neural-interface/lib/teams/index.js +7 -7
  206. package/neural-interface/lib/teams/integration.js +40 -40
  207. package/neural-interface/lib/teams/landing.js +6 -6
  208. package/neural-interface/lib/teams/recovery.js +24 -23
  209. package/neural-interface/lib/teams/scheduler.js +194 -95
  210. package/neural-interface/lib/teams/state.js +14 -14
  211. package/neural-interface/lib/teams/worktrees.js +27 -27
  212. package/neural-interface/lib/terminal-token-redaction.js +83 -0
  213. package/neural-interface/lib/whatsapp/bridge.js +54 -7
  214. package/neural-interface/lib/worker-confinement.js +47 -2
  215. package/neural-interface/lib/worker-mcp-channel.js +2 -0
  216. package/neural-interface/lib/worker-resume.js +5 -0
  217. package/neural-interface/lib/worker-stop.js +86 -0
  218. package/neural-interface/package-lock.json +5 -5
  219. package/neural-interface/package.json +1 -1
  220. package/neural-interface/public/extension-setup.html +5 -2
  221. package/neural-interface/public/index.html +233 -24
  222. package/neural-interface/public/onboarding.html +259 -34
  223. package/neural-interface/public/shared/agents/studio/ax-library.js +0 -6
  224. package/neural-interface/public/shared/agents/studio/ax-main.js +14 -7
  225. package/neural-interface/public/shared/agy/agy-options.js +11 -0
  226. package/neural-interface/public/shared/agy/agy-panel.js +67 -20
  227. package/neural-interface/public/shared/agy/agy-styles.js +14 -12
  228. package/neural-interface/public/shared/agy/agy-tabs-logic.js +4 -1
  229. package/neural-interface/public/shared/api.js +1 -1
  230. package/neural-interface/public/shared/assistant/asst-api.js +28 -3
  231. package/neural-interface/public/shared/assistant/asst-brain-picker.js +13 -6
  232. package/neural-interface/public/shared/assistant/asst-control.js +2 -0
  233. package/neural-interface/public/shared/assistant/asst-motion-gate.js +78 -4
  234. package/neural-interface/public/shared/assistant/asst-panel.js +87 -3
  235. package/neural-interface/public/shared/assistant/asst-rack-styles.js +27 -0
  236. package/neural-interface/public/shared/assistant/asst-render.js +243 -44
  237. package/neural-interface/public/shared/assistant/asst-route.js +100 -21
  238. package/neural-interface/public/shared/assistant/asst-routes-editor.js +1 -1
  239. package/neural-interface/public/shared/assistant/asst-shell-logic.js +200 -0
  240. package/neural-interface/public/shared/assistant/asst-shell.js +111 -0
  241. package/neural-interface/public/shared/assistant/asst-sidepanel.js +4 -2
  242. package/neural-interface/public/shared/assistant/asst-state.js +11 -0
  243. package/neural-interface/public/shared/assistant/asst-styles.js +11 -23
  244. package/neural-interface/public/shared/assistant/route-identity.js +2 -1
  245. package/neural-interface/public/shared/cdx/cdx-render.js +9 -0
  246. package/neural-interface/public/shared/cdx/cdx-settings.js +3 -1
  247. package/neural-interface/public/shared/cdx/cdx-styles.js +6 -0
  248. package/neural-interface/public/shared/cdx/cdx-tabs.js +54 -9
  249. package/neural-interface/public/shared/client-diagnostics.js +94 -0
  250. package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
  251. package/neural-interface/public/shared/cp/cp-styles.js +1 -1
  252. package/neural-interface/public/shared/effort-i18n.js +118 -0
  253. package/neural-interface/public/shared/extension-setup/es-page.js +10 -4
  254. package/neural-interface/public/shared/extension-setup/es-view.js +25 -10
  255. package/neural-interface/public/shared/html-shell.js +4 -52
  256. package/neural-interface/public/shared/loading-diagnostic-entry.js +64 -0
  257. package/neural-interface/public/shared/memory-store-wait.js +52 -0
  258. package/neural-interface/public/shared/morelogin-profile-field.js +1 -1
  259. package/neural-interface/public/shared/mtc/mtc-logic.js +2 -1
  260. package/neural-interface/public/shared/mtc/mtc-panel.js +25 -3
  261. package/neural-interface/public/shared/mtc/mtc-styles.js +13 -12
  262. package/neural-interface/public/shared/ocp-v2/ocp-v2-childpanel.js +7 -0
  263. package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +5 -0
  264. package/neural-interface/public/shared/ocp-v2/ocp-v2-location-logic.js +109 -0
  265. package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +1 -0
  266. package/neural-interface/public/shared/ocp-v2/ocp-v2-modelpicker.js +8 -1
  267. package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +152 -8
  268. package/neural-interface/public/shared/ocp-v2/ocp-v2-rehydrate.js +7 -1
  269. package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +53 -4
  270. package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +52 -6
  271. package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +22 -2
  272. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-block.js +165 -0
  273. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +346 -0
  274. package/neural-interface/public/shared/ocp-v2/ocp-v2-shell.js +108 -0
  275. package/neural-interface/public/shared/ocp-v2/ocp-v2-state.js +49 -3
  276. package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +67 -93
  277. package/neural-interface/public/shared/ocp-v2/ocp-v2-tools-logic.js +20 -5
  278. package/neural-interface/public/shared/ocp-v2/ocp-v2-tools.js +7 -1
  279. package/neural-interface/public/shared/ocp-v2/ocp-v2-variantpicker.js +17 -6
  280. package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +7 -2
  281. package/neural-interface/public/shared/output-format.js +294 -0
  282. package/neural-interface/public/shared/provider-icons.js +6 -0
  283. package/neural-interface/public/shared/schedules-view.js +2 -1
  284. package/neural-interface/public/shared/server-presence.js +77 -0
  285. package/neural-interface/public/shared/settings/settings-backup-contents.js +241 -0
  286. package/neural-interface/public/shared/settings/settings-backup-download.js +298 -0
  287. package/neural-interface/public/shared/settings/settings-backup-encryption-pane.js +335 -0
  288. package/neural-interface/public/shared/settings/settings-backup-encryption.js +545 -0
  289. package/neural-interface/public/shared/settings/settings-browser-extension.js +54 -12
  290. package/neural-interface/public/shared/settings/settings-ia.js +1 -1
  291. package/neural-interface/public/shared/shell-stop-view.js +83 -0
  292. package/neural-interface/public/shared/skills/studio/sx-geometry.js +12 -3
  293. package/neural-interface/public/shared/skills/studio/sx-main.js +14 -7
  294. package/neural-interface/public/shared/studio-attention.js +6 -0
  295. package/neural-interface/public/shared/styles.css +341 -437
  296. package/neural-interface/public/shared/tour/tour-actor.js +14 -3
  297. package/neural-interface/public/shared/transcript-rows.js +28 -3
  298. package/neural-interface/public/shared/tray-auto-close.js +49 -6
  299. package/neural-interface/public/shared/ui-agents.js +1 -2
  300. package/neural-interface/public/shared/ui-automation-studio.js +168 -108
  301. package/neural-interface/public/shared/ui-claude-panel.js +62 -65
  302. package/neural-interface/public/shared/ui-loading.js +124 -17
  303. package/neural-interface/public/shared/ui-native-loop-router.js +52 -0
  304. package/neural-interface/public/shared/ui-navbar.js +2 -1
  305. package/neural-interface/public/shared/ui-output.js +533 -0
  306. package/neural-interface/public/shared/ui-schedules-studio.js +165 -128
  307. package/neural-interface/public/shared/ui-scroll-follow.js +101 -6
  308. package/neural-interface/public/shared/ui-sessions.js +2 -2
  309. package/neural-interface/public/shared/ui-settings-entry.js +18 -0
  310. package/neural-interface/public/shared/ui-settings.js +224 -65
  311. package/neural-interface/public/shared/ui-sidepanel-tray.js +3 -2
  312. package/neural-interface/public/shared/ui-tooltip.js +16 -0
  313. package/neural-interface/public/shared/ui-tutorial.js +5 -6
  314. package/neural-interface/public/shared/ui-worker-end.js +27 -8
  315. package/neural-interface/public/shared/worker-end.js +9 -4
  316. package/neural-interface/public/variant/2d/main.js +5 -0
  317. package/neural-interface/public/variant/3d/app.js +10 -0
  318. package/neural-interface/public/variant/3d/main.js +5 -1
  319. package/neural-interface/scripts/scratch-retention.mjs +20 -0
  320. package/neural-interface/server.js +725 -173
  321. package/npm-shrinkwrap.json +5 -5
  322. package/package.json +1 -2
  323. package/scripts/restore-data-home-from-backup.mjs +175 -8
  324. package/setup.js +18 -4
  325. package/browser-extension/content.js +0 -189
  326. package/browser-extension/engine.js +0 -508
  327. package/browser-extension/icons/icon-128.png +0 -0
  328. package/browser-extension/icons/icon-16.png +0 -0
  329. package/browser-extension/icons/icon-32.png +0 -0
  330. package/browser-extension/icons/icon-48.png +0 -0
  331. package/browser-extension/icons/status-off-16.png +0 -0
  332. package/browser-extension/icons/status-off-32.png +0 -0
  333. package/browser-extension/icons/status-off-48.png +0 -0
  334. package/browser-extension/icons/status-on-16.png +0 -0
  335. package/browser-extension/icons/status-on-32.png +0 -0
  336. package/browser-extension/icons/status-on-48.png +0 -0
  337. package/browser-extension/manifest.json +0 -56
  338. package/browser-extension/popup-strings.js +0 -250
  339. package/browser-extension/popup-view.js +0 -151
  340. package/browser-extension/popup.css +0 -166
  341. package/browser-extension/popup.html +0 -108
  342. package/browser-extension/popup.js +0 -359
  343. package/browser-extension/service-worker.js +0 -275
  344. package/browser-extension/setup-content.js +0 -36
  345. package/browser-extension/tokens.css +0 -326
@@ -0,0 +1,294 @@
1
+ // ═══════════════════════════════════════════
2
+ // SynaBun Neural Interface — an agent's answer as a readable document: the decisions
3
+ // ═══════════════════════════════════════════
4
+ //
5
+ // The six side panels (Assistant, Claude Code, Codex, OpenCode, Antigravity, Maritaca) show an agent's Markdown
6
+ // through the same sanitiser and, since this module, as the same document: one type scale, one spacing rhythm,
7
+ // one table, one code block. This is the part that needs no page: the words, the markup added to a panel's
8
+ // SANITISED Markdown (so a stream, a re-render, a morph and a stored transcript all keep it, exactly like the
9
+ // Copy button of code-copy.js), and what a table copies. ui-output.js gives it the page: the stylesheet, the
10
+ // one click listener per document, the wider view of a table.
11
+ //
12
+ // What it adds, and nothing else:
13
+ // · a frame around every table (it wraps at words to fit the panel, and scrolls sideways inside the frame only
14
+ // when its columns cannot fit), with Copy and, for a table worth it, Expand; a numeric column is
15
+ // right-aligned and a column of sentences keeps a readable width;
16
+ // · a class on a task-list item (the sanitiser turns its checkbox into ☑ / ☐: no bullet beside the box);
17
+ // · the language of a fenced block on its <pre> (drawn as a label) and the lines of a diff as add / remove.
18
+ //
19
+ // Run it on the sanitiser's output, never before: the allowlist takes a model's own div, button and class out,
20
+ // so a reply cannot forge a frame or a button. It never adds a link, a handler or a style.
21
+ //
22
+ // No imports and no `document`: loaded by `node --test` as it is, and by the Markdown renderers.
23
+
24
+ /** The English of `output.*` in i18n/en.json (tests/output-format.test.mjs keeps them equal). */
25
+ export const OUTPUT_COPY = Object.freeze({
26
+ copy: 'Copy',
27
+ copied: 'Copied',
28
+ failed: 'Not copied',
29
+ copyTable: 'Copy table',
30
+ tableCopied: 'Table copied',
31
+ tableFailed: 'Could not copy the table.',
32
+ expand: 'Expand',
33
+ expandTable: 'Open the table in a wider view',
34
+ tableTitle: 'Table',
35
+ tableSize: '{rows} rows · {columns} columns',
36
+ close: 'Close',
37
+ });
38
+
39
+ export const TABLE_FRAME_CLASS = 'sb-table';
40
+ export const TABLE_SCROLL_CLASS = 'sb-table-scroll';
41
+ export const TABLE_TOOLS_CLASS = 'sb-table-tools';
42
+ export const TABLE_BUTTON_CLASS = 'sb-table-btn';
43
+ export const NUMERIC_CLASS = 'sb-num';
44
+ export const LONG_CLASS = 'sb-long';
45
+ /** A column with a cell of at least this many characters in at least LONG_CELL_WORDS words holds sentences. */
46
+ export const LONG_CELL_CHARS = 28;
47
+ export const LONG_CELL_WORDS = 4;
48
+ export const TASK_CLASS = 'sb-task';
49
+
50
+ /** How long "Copied" (and the failure) stays on a table's button: the code block's timing. */
51
+ export const OUTPUT_FEEDBACK_MS = Object.freeze({ copied: 1500, failed: 4000 });
52
+
53
+ let translate = null;
54
+
55
+ /** Where a sentence comes from in the active locale: `fn(key, params)`, or a falsy value for the English. */
56
+ export function setOutputTranslator(fn) { translate = typeof fn === 'function' ? fn : null; }
57
+
58
+ /** An `output.*` sentence in the active locale, else the English. */
59
+ export function outputText(key, params = {}) {
60
+ let text = '';
61
+ try { text = translate?.(key, params) || ''; } catch { text = ''; }
62
+ if (!text || typeof text !== 'string') text = OUTPUT_COPY[key] ?? key;
63
+ return text.replace(/\{(\w+)\}/g, (whole, name) => (params[name] != null ? String(params[name]) : whole));
64
+ }
65
+
66
+ const escAttr = (value) => String(value ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
67
+
68
+ // A number as a reader sees one: an optional sign or comparison, a currency, digits with their separators, and a
69
+ // short unit (%, ms, s, MB, k, ×). A date (2026-11-21) or a time (12:30) is not one: nothing is aligned by it.
70
+ const NUMERIC_RE = /^[+\-−–~≈<>≤≥]?\s?(?:US\$|R\$|[$€£¥])?\s?\d[\d.,\s_]*(?:\s?(?:%|×|[a-zA-Zµ°]{1,5}(?:\/[a-zA-Z]{1,4})?))?$/;
71
+ const BLANK_RE = /^(?:|[-–—]|n\/a|—)$/i;
72
+
73
+ /** True when a cell's text is a number (see above). */
74
+ export function isNumericText(text) { return NUMERIC_RE.test(String(text ?? '').trim()); }
75
+
76
+ /**
77
+ * Which columns of a table hold numbers: every filled cell of the body is one, and at least one is filled.
78
+ * @param {string[][]} bodyRows the body's cells as text
79
+ * @returns {boolean[]} one flag per column
80
+ */
81
+ export function numericColumns(bodyRows) {
82
+ const rows = Array.isArray(bodyRows) ? bodyRows : [];
83
+ const width = rows.reduce((max, row) => Math.max(max, row.length), 0);
84
+ const flags = [];
85
+ for (let col = 0; col < width; col += 1) {
86
+ let filled = 0;
87
+ let numeric = true;
88
+ for (const row of rows) {
89
+ const text = String(row[col] ?? '').trim();
90
+ if (BLANK_RE.test(text)) continue;
91
+ filled += 1;
92
+ if (!NUMERIC_RE.test(text)) { numeric = false; break; }
93
+ }
94
+ flags.push(numeric && filled > 0);
95
+ }
96
+ return flags;
97
+ }
98
+
99
+ const ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '"', '#39': "'", nbsp: ' ' };
100
+ // The text of a serialised cell: its tags out, the few entities a serialiser writes read back.
101
+ const cellText = (html) => String(html).replace(/<[^>]*>/g, '').replace(/&(amp|lt|gt|quot|#39|nbsp);/g, (_, name) => ENTITIES[name]).trim();
102
+
103
+ const ROW_RE = /<tr>([\s\S]*?)<\/tr>/g;
104
+ const CELL_RE = /<(t[hd])((?:\s[^>]*)?)>([\s\S]*?)<\/t[hd]>/g;
105
+
106
+ /**
107
+ * Which columns of a table hold sentences: some cell (the header's too) is LONG_CELL_CHARS or longer and has
108
+ * LONG_CELL_WORDS words or more. A long path or identifier is one word: it wraps where it can, and is not one.
109
+ * @param {string[][]} rows every row's cells as text
110
+ * @returns {boolean[]} one flag per column
111
+ */
112
+ export function longColumns(rows) {
113
+ const flags = [];
114
+ for (const row of Array.isArray(rows) ? rows : []) {
115
+ row.forEach((cell, col) => {
116
+ const text = String(cell ?? '').trim();
117
+ if (text.length >= LONG_CELL_CHARS && text.split(/\s+/).length >= LONG_CELL_WORDS) flags[col] = true;
118
+ });
119
+ }
120
+ return Array.from(flags, Boolean);
121
+ }
122
+
123
+ // A sanitised table with `class="sb-num"` on the cells of its numeric columns and `class="sb-long"` on those of
124
+ // its columns of sentences. A numeric column the writer aligned (`---:` in Markdown: the sanitiser keeps
125
+ // `align`) is left as written, and so is a table that holds a table.
126
+ function markColumns(table) {
127
+ if (table.indexOf('<table', 1) !== -1) return table;
128
+ const bodyStart = table.indexOf('<tbody>');
129
+ const head = bodyStart === -1 ? '' : table.slice(0, bodyStart);
130
+ const body = bodyStart === -1 ? table : table.slice(bodyStart);
131
+ const rows = [];
132
+ for (const row of body.matchAll(ROW_RE)) {
133
+ const cells = [...row[1].matchAll(CELL_RE)];
134
+ if (cells.some((cell) => /\s(?:colspan|rowspan)=/i.test(cell[2]))) return table;
135
+ rows.push(cells.map((cell) => cellText(cell[3])));
136
+ }
137
+ const bodyRows = bodyStart === -1 ? rows.slice(1) : rows.slice();
138
+ if (!bodyRows.length) return table;
139
+ // The header's cells count for a column's width, wherever the header is.
140
+ if (bodyStart !== -1) for (const row of head.matchAll(ROW_RE)) rows.push([...row[1].matchAll(CELL_RE)].map((cell) => cellText(cell[3])));
141
+ const numeric = numericColumns(bodyRows);
142
+ const long = longColumns(rows);
143
+ if (!numeric.some(Boolean) && !long.some(Boolean)) return table;
144
+ const mark = (part) => part.replace(ROW_RE, (whole, inner) => {
145
+ let col = -1;
146
+ return `<tr>${inner.replace(CELL_RE, (cell, tag, attrs, content) => {
147
+ col += 1;
148
+ if (/\sclass=/i.test(attrs)) return cell;
149
+ const cls = numeric[col] && !/\salign=/i.test(attrs) ? NUMERIC_CLASS : long[col] && !numeric[col] ? LONG_CLASS : '';
150
+ return cls ? `<${tag}${attrs} class="${cls}">${content}</${tag}>` : cell;
151
+ })}</tr>`;
152
+ });
153
+ return mark(head) + mark(body);
154
+ }
155
+
156
+ /** How many body rows and columns a serialised table has. */
157
+ export function tableSize(table) {
158
+ const rows = [...String(table).matchAll(ROW_RE)];
159
+ const hasHead = /<thead>/i.test(table);
160
+ const columns = rows.length ? [...rows[0][1].matchAll(CELL_RE)].length : 0;
161
+ return { rows: Math.max(0, rows.length - (hasHead || rows.length > 1 ? 1 : 0)), columns };
162
+ }
163
+
164
+ function tableButton(action, label, name) {
165
+ return `<button type="button" class="${TABLE_BUTTON_CLASS}" data-sb-act="${action}" data-label="${escAttr(label)}" aria-label="${escAttr(name)}"></button>`;
166
+ }
167
+
168
+ /** The strip above a table: its size (drawn by CSS for a table that is worth it), Expand and Copy. */
169
+ export function tableToolsHtml({ rows = 0, columns = 0 } = {}) {
170
+ return `<div class="${TABLE_TOOLS_CLASS}" data-rows="${rows}" data-columns="${columns}" data-label="${escAttr(outputText('tableSize', { rows, columns }))}">`
171
+ + `${tableButton('expand', outputText('expand'), outputText('expandTable'))}${tableButton('copy', outputText('copy'), outputText('copyTable'))}</div>`;
172
+ }
173
+
174
+ const FRAME_OPEN = `<div class="${TABLE_SCROLL_CLASS}">`;
175
+
176
+ /** One sanitised `<table>…</table>` inside its frame. */
177
+ export function tableFrameHtml(table) {
178
+ const marked = markColumns(table);
179
+ return `<div class="${TABLE_FRAME_CLASS}">${tableToolsHtml(tableSize(marked))}${FRAME_OPEN}${marked}</div></div>`;
180
+ }
181
+
182
+ // Every outermost table of a serialised document through `fn`; one already inside a frame is left alone, so the
183
+ // result is the same however often this runs.
184
+ function mapTables(html, fn) {
185
+ const token = /<table>|<\/table>/gi;
186
+ let out = '';
187
+ let last = 0;
188
+ let depth = 0;
189
+ let start = -1;
190
+ for (let match = token.exec(html); match; match = token.exec(html)) {
191
+ if (match[0][1] !== '/') {
192
+ if (depth === 0) start = match.index;
193
+ depth += 1;
194
+ } else if (depth > 0) {
195
+ depth -= 1;
196
+ if (depth !== 0) continue;
197
+ const end = match.index + match[0].length;
198
+ const framed = html.slice(Math.max(0, start - FRAME_OPEN.length), start) === FRAME_OPEN;
199
+ out += html.slice(last, start) + (framed ? html.slice(start, end) : fn(html.slice(start, end)));
200
+ last = end;
201
+ }
202
+ }
203
+ return out + html.slice(last);
204
+ }
205
+
206
+ const TASK_RE = /<li>(\s*(?:<p>)?)(☑|☐) /g;
207
+ const LANG_RE = /<pre><code class="language-([\w+#.-]{1,40})">/g;
208
+ const DIFF_RE = /(<pre data-lang="diff"><code class="language-diff">)([\s\S]*?)(<\/code>)/g;
209
+
210
+ /** The kind of a diff's line as a class (`sb-diff-add`, `-del`, `-hunk`, `-file`), or '' for a line of context. */
211
+ export function diffLineClass(line) {
212
+ if (/^(?:\+\+\+ |--- |diff |index )/.test(line)) return 'sb-diff-file';
213
+ if (line.startsWith('@@')) return 'sb-diff-hunk';
214
+ if (line.startsWith('+')) return 'sb-diff-add';
215
+ if (line.startsWith('-')) return 'sb-diff-del';
216
+ return '';
217
+ }
218
+
219
+ // The lines of a diff block, each added, removed, hunk or file line in a span of its kind. The text is untouched
220
+ // (what the block copies is what was written); a block that already holds markup is left as it is.
221
+ export function markDiffLines(body) {
222
+ if (body.includes('<')) return body;
223
+ return body.split('\n').map((line) => {
224
+ const cls = diffLineClass(line);
225
+ return cls && line ? `<span class="${cls}">${line}</span>` : line;
226
+ }).join('\n');
227
+ }
228
+
229
+ /**
230
+ * Sanitised Markdown HTML as a readable document: tables in their frames, task items, code languages, diff lines.
231
+ * Idempotent. `diff: false` leaves a diff block's lines alone (a panel that highlights code itself).
232
+ */
233
+ export function withOutputFrames(html, { diff = true } = {}) {
234
+ let out = typeof html === 'string' ? html : '';
235
+ if (!out) return out;
236
+ if (/<table>/i.test(out)) out = mapTables(out, tableFrameHtml);
237
+ if (out.includes('☑') || out.includes('☐')) {
238
+ out = out.replace(TASK_RE, (whole, lead, box) => `<li class="${TASK_CLASS}${box === '☑' ? ` ${TASK_CLASS}-done` : ''}">${lead}<span class="${TASK_CLASS}-box">${box}</span> `);
239
+ }
240
+ if (out.includes('<pre><code class="language-')) out = out.replace(LANG_RE, '<pre data-lang="$1"><code class="language-$1">');
241
+ if (diff && out.includes('data-lang="diff"')) out = out.replace(DIFF_RE, (whole, open, body, close) => open + markDiffLines(body) + close);
242
+ return out;
243
+ }
244
+
245
+ const tagOf = (node) => String(node?.localName || node?.nodeName || '').toLowerCase();
246
+
247
+ function nodeText(node) {
248
+ let out = '';
249
+ const walk = (parent) => {
250
+ for (const child of parent.childNodes || []) {
251
+ if (child.nodeType === 3 || child.nodeType === 4) { out += child.data ?? child.nodeValue ?? ''; continue; }
252
+ if (child.nodeType !== 1) continue;
253
+ const tag = tagOf(child);
254
+ if (tag === 'button') continue;
255
+ if (tag === 'br') { out += ' '; continue; }
256
+ walk(child);
257
+ }
258
+ };
259
+ walk(node);
260
+ return out.replace(/\s+/g, ' ').trim();
261
+ }
262
+
263
+ /**
264
+ * A table element's cells as text, row by row (the header first). Works on any DOM, a test's included.
265
+ * @returns {string[][]}
266
+ */
267
+ export function tableMatrix(table) {
268
+ const rows = [];
269
+ const walk = (node) => {
270
+ for (const child of node?.childNodes || []) {
271
+ if (child.nodeType !== 1) continue;
272
+ const tag = tagOf(child);
273
+ if (tag === 'tr') rows.push([...child.childNodes].filter((cell) => cell.nodeType === 1 && /^t[hd]$/.test(tagOf(cell))).map(nodeText));
274
+ else if (tag === 'thead' || tag === 'tbody' || tag === 'tfoot') walk(child);
275
+ }
276
+ };
277
+ walk(table);
278
+ return rows;
279
+ }
280
+
281
+ /** A table as tab-separated text: what a spreadsheet, a chat and a terminal all read. */
282
+ export function matrixToTsv(matrix) {
283
+ return (matrix || []).map((row) => row.map((cell) => String(cell ?? '').replace(/[\t\r\n]+/g, ' ')).join('\t')).join('\n');
284
+ }
285
+
286
+ const escText = (value) => String(value ?? '').replace(/[&<>]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;' }[c]));
287
+
288
+ /** The same table as plain, unstyled HTML (text only): what a document or a mail pastes as a table. */
289
+ export function matrixToHtml(matrix) {
290
+ const rows = matrix || [];
291
+ if (!rows.length) return '';
292
+ const line = (row, tag) => `<tr>${row.map((cell) => `<${tag}>${escText(cell)}</${tag}>`).join('')}</tr>`;
293
+ return `<table><thead>${line(rows[0], 'th')}</thead><tbody>${rows.slice(1).map((row) => line(row, 'td')).join('')}</tbody></table>`;
294
+ }
@@ -33,3 +33,9 @@ export function getProviderMeta(providerId = 'claude-code') {
33
33
  }
34
34
 
35
35
  export { PROVIDER_META };
36
+
37
+ /** OpenCode stores a model as providerID/modelID or as its serialized string. */
38
+ export function isMaritacaModel(model) {
39
+ const provider = typeof model === 'string' ? model.split('/', 1)[0] : model?.providerID;
40
+ return typeof provider === 'string' && provider.toLowerCase() === 'maritaca';
41
+ }
@@ -1,3 +1,4 @@
1
+ import { isPersonalStop } from './worker-end.js';
1
2
  import { toolListView } from './tool-list-view.js';
2
3
  // SynaBun Neural Interface — what the Schedules window shows, without the page.
3
4
  // Which schedules a view lists and in which order, how a schedule's state reads, and the cron
@@ -230,7 +231,7 @@ export function lastRunState(schedule) {
230
231
  const head = (colon >= 0 ? text.slice(0, colon) : text).trim();
231
232
  const reason = colon >= 0 ? text.slice(colon + 1).trim() : '';
232
233
  if (head === 'error') return { kind: 'failed', label: scheduleWord('runFailed'), reason: reason || scheduleWord('runFailedReason') };
233
- if (head === 'stopped') return { kind: 'stopped', label: scheduleWord('runStopped'), reason: reason === 'user' ? scheduleWord('runStoppedByYou') : reason };
234
+ if (head === 'stopped') return { kind: 'stopped', label: scheduleWord('runStopped'), reason: reason === 'user' ? (isPersonalStop(schedule.lastStopProvenance) ? scheduleWord('runStoppedByYou') : '') : reason };
234
235
  if (head === 'interrupted') return { kind: 'interrupted', label: scheduleWord('runInterrupted'), reason };
235
236
  return { kind: 'other', label: head.charAt(0).toUpperCase() + head.slice(1), reason };
236
237
  }
@@ -0,0 +1,77 @@
1
+ // ═══════════════════════════════════════════
2
+ // SynaBun Neural Interface — is the server gone, or only slow
3
+ // What the page concludes from health probes that were not answered.
4
+ // DOM-free and dependency-free (unit-tested under Node).
5
+ //
6
+ // The page asks GET /api/health every 3 s and gives each request 3 s. It used
7
+ // to show "Server offline" after two requests in a row without an answer: six
8
+ // seconds. On 2026-11-21 a server that never stopped (same boot id before and
9
+ // after, its WebSockets still open) was shown as offline that way, twice,
10
+ // while it worked through slow database statements during and after a 9.4 GB
11
+ // backup. Not answering in time is not being gone, and the two look different
12
+ // from here:
13
+ //
14
+ // refused the request failed at once: nothing listens on the port (the
15
+ // process ended), or what answered is not the server. Asked once
16
+ // more right away; refused again is offline. A real stop is still
17
+ // reported within the time of two failed connections.
18
+ // timeout the connection was taken and no answer came in time: the
19
+ // process is there and busy (or the machine is). Nothing is shown
20
+ // until that has lasted `slowGraceMs` over at least `slowMisses`
21
+ // probes in a row; one answer in between starts the count again.
22
+ // A hung server is still reported, just not a slow one.
23
+ //
24
+ // A hidden tab never concludes "offline" from timeouts: browsers hold back a
25
+ // background tab's timers and requests, so a late answer there says nothing
26
+ // about the server. It looks again the moment it is shown (`shown()`).
27
+ // ═══════════════════════════════════════════
28
+
29
+ export const PRESENCE_LIMITS = {
30
+ slowGraceMs: 20000, // unanswered (but not refused) for this long before the offline screen
31
+ slowMisses: 3, // and at least this many probes in a row
32
+ };
33
+
34
+ /** How a failed probe ended: 'timeout' (given up on waiting) or 'refused' (nothing took it, or not the server's answer). */
35
+ export function probeFailureKind(error) {
36
+ const name = String(error?.name || '');
37
+ return name === 'TimeoutError' || name === 'AbortError' ? 'timeout' : 'refused';
38
+ }
39
+
40
+ /**
41
+ * The misses of one page, in a row.
42
+ * missed(kind, { hidden, confirmed }) → 'confirm' | 'offline' | 'wait'
43
+ * 'confirm' refused once: ask again right away, then call missed(kind, { confirmed: true })
44
+ * 'offline' show the offline screen
45
+ * 'wait' slow, or a hidden tab that cannot tell: show nothing, keep probing
46
+ * answered() → { recovered, misses, ms } an answer from the server ends the row
47
+ * snapshot() → { misses, ms, held } | null the row under way (held: 'slow' | 'hidden' | null)
48
+ */
49
+ export function createServerPresence({ limits = PRESENCE_LIMITS, now = () => Date.now() } = {}) {
50
+ const lim = { ...PRESENCE_LIMITS, ...limits };
51
+ let row = null; // { since, misses, held }
52
+
53
+ return {
54
+ missed(kind, { hidden = false, confirmed = false } = {}) {
55
+ if (!row) row = { since: now(), misses: 0, held: null };
56
+ row.misses += 1;
57
+ if (kind !== 'timeout') {
58
+ row.held = null;
59
+ return confirmed ? 'offline' : 'confirm';
60
+ }
61
+ if (hidden) { row.held = 'hidden'; return 'wait'; }
62
+ if (row.misses >= lim.slowMisses && now() - row.since >= lim.slowGraceMs) { row.held = null; return 'offline'; }
63
+ row.held = 'slow';
64
+ return 'wait';
65
+ },
66
+ answered() {
67
+ const had = row;
68
+ row = null;
69
+ return had ? { recovered: true, misses: had.misses, ms: Math.max(0, now() - had.since) } : { recovered: false, misses: 0, ms: 0 };
70
+ },
71
+ snapshot() {
72
+ return row ? { misses: row.misses, ms: Math.max(0, now() - row.since), held: row.held } : null;
73
+ },
74
+ /** The offline screen is up, or the page gave up watching: whatever comes next is a new row. */
75
+ reset() { row = null; },
76
+ };
77
+ }
@@ -0,0 +1,241 @@
1
+ // ═══════════════════════════════════════════
2
+ // SETTINGS — What to back up
3
+ // ═══════════════════════════════════════════
4
+ //
5
+ // Settings → Memory & backups → Backups → What to back up. A backup is made of groups (lib/backup-groups.js) and the
6
+ // owner switches each on or off, with its size beside it; the choice is the server's (lib/backup-contents.js, GET and
7
+ // PUT /api/system/backup/contents) and applies to every manual and scheduled backup. The sizes are measured on a
8
+ // worker thread there: this page reads what is measured and asks again while a measurement runs.
9
+ // Pure: no DOM and no import, so node runs it (tests/settings-backup-contents.test.mjs).
10
+ //
11
+ // readBackupContentsResponse({ status, body, error }) what the server answered → a reading
12
+ // describeBackupContents(model, { tx }) the list as ui-settings.js draws it
13
+ // describeRestoreContents(contents, { tx }) what a backup holds, for the restore dialog
14
+ // createBackupContentsController({ fetch, render, … }) load, switch a group, measure again
15
+ //
16
+ // `tx(key, params)` is the caller's translate function over the settings.redesign.* strings (the kit's `tx`).
17
+ // A server started before these routes existed answers 404: the list then says a restart is missing, and until
18
+ // then every backup holds everything, as it always did.
19
+
20
+ const K = 'settings.redesign.server';
21
+
22
+ export const BACKUP_CONTENTS_URL = '/api/system/backup/contents';
23
+
24
+ // Every key written out: the settings copy tools find a key by its literal.
25
+ const GROUP_COPY = {
26
+ memories: { label: `${K}.backupGroupMemories`, help: `${K}.backupGroupMemoriesHelp` },
27
+ settings: { label: `${K}.backupGroupSettings`, help: `${K}.backupGroupSettingsHelp` },
28
+ conversations: { label: `${K}.backupGroupConversations`, help: `${K}.backupGroupConversationsHelp` },
29
+ media: { label: `${K}.backupGroupMedia`, help: `${K}.backupGroupMediaHelp` },
30
+ caches: { label: `${K}.backupGroupCaches`, help: `${K}.backupGroupCachesHelp` },
31
+ scratch: { label: `${K}.backupGroupScratch`, help: `${K}.backupGroupScratchHelp` },
32
+ };
33
+ const KIND_COPY = {
34
+ irreplaceable: `${K}.backupKindIrreplaceable`,
35
+ regenerable: `${K}.backupKindRegenerable`,
36
+ temporary: `${K}.backupKindTemporary`,
37
+ };
38
+
39
+ const clean = (value, max = 400) => {
40
+ const text = String(value ?? '').replace(/\s+/g, ' ').trim();
41
+ return text.length > max ? `${text.slice(0, max - 1)}…` : text;
42
+ };
43
+
44
+ /** A size with its unit: KB below a megabyte, MB below a gigabyte, GB from there. '' for what is not a size. */
45
+ export function formatContentsSize(bytes) {
46
+ const size = Number(bytes);
47
+ if (bytes == null || !Number.isFinite(size) || size < 0) return '';
48
+ if (size >= 1024 ** 3) return `${(size / 1024 ** 3).toFixed(2)} GB`;
49
+ if (size >= 1024 ** 2) return `${(size / 1024 ** 2).toFixed(size >= 100 * 1024 ** 2 ? 0 : 1)} MB`;
50
+ return `${Math.max(size > 0 ? 1 : 0, Math.round(size / 1024))} KB`;
51
+ }
52
+
53
+ /** The name of a group as the page says it; a group this page does not know keeps its id. */
54
+ export function backupGroupLabel(id, tx) {
55
+ return GROUP_COPY[id] ? tx(GROUP_COPY[id].label) : String(id);
56
+ }
57
+
58
+ /**
59
+ * What the server answered.
60
+ * ready `groups` [{ id, kind, enabled, files, bytes, archiveBytes }], `totals`, `never`, `irreplaceableOff`,
61
+ * `estimate` { state: 'none' | 'measuring' | 'ready' | 'failed', error }
62
+ * old-server 404: the running server was started before these routes existed
63
+ * refused an answer with an error and no state (`message`, `code`)
64
+ * unreadable anything else; `message`
65
+ */
66
+ export function readBackupContentsResponse({ status = 0, body = null, error = null } = {}) {
67
+ const code = Number(status) || 0;
68
+ if (code === 404) return { state: 'old-server' };
69
+ if (body && typeof body === 'object' && Array.isArray(body.groups) && code >= 200 && code < 300) {
70
+ // An id is used in the rows' element ids: only the shape a group id has is let through.
71
+ const groups = body.groups.filter(group => group && typeof group.id === 'string' && /^[a-z][a-z0-9-]{0,39}$/.test(group.id)).map(group => ({
72
+ id: group.id,
73
+ kind: typeof group.kind === 'string' ? group.kind : 'irreplaceable',
74
+ enabled: group.enabled === true,
75
+ files: Number.isFinite(group.files) ? group.files : null,
76
+ bytes: Number.isFinite(group.bytes) ? group.bytes : null,
77
+ archiveBytes: Number.isFinite(group.archiveBytes) ? group.archiveBytes : null,
78
+ }));
79
+ const estimate = body.estimate && typeof body.estimate === 'object' ? body.estimate : {};
80
+ return {
81
+ state: 'ready', groups,
82
+ totals: body.totals && typeof body.totals === 'object' ? body.totals : null,
83
+ never: body.never && typeof body.never === 'object' ? body.never : null,
84
+ irreplaceableOff: Array.isArray(body.irreplaceableOff) ? body.irreplaceableOff.filter(id => typeof id === 'string') : [],
85
+ estimate: { state: typeof estimate.state === 'string' ? estimate.state : 'none', error: clean(estimate.error) || null },
86
+ };
87
+ }
88
+ if (body && typeof body === 'object' && body.error) return { state: 'refused', message: clean(body.error), code: body.code || null };
89
+ return { state: 'unreadable', message: clean(error?.message || error) || (code ? `HTTP ${code}` : '') };
90
+ }
91
+
92
+ /**
93
+ * The list. `model`: `{ reading, notice, saving }`, the controller's. →
94
+ * available the server has the choice (false: `note` says why not, and no row is drawn)
95
+ * rows [{ id, label, help, kind, kindLabel, enabled, size, busy }] `size` '' while it is not measured
96
+ * total the size of a backup made with this choice ('' while it is not measured)
97
+ * everything the size with every group on, when that is more ('' otherwise)
98
+ * warning which irreplaceable groups are switched off (null: none)
99
+ * never what no backup holds, with its size (null while it is not measured)
100
+ * note a refusal, a failed save or a failed measurement (null: nothing)
101
+ * measuring a measurement runs
102
+ */
103
+ export function describeBackupContents({ reading = null, notice = null, saving = null } = {}, { tx }) {
104
+ if (reading?.state === 'old-server') return { available: false, rows: [], total: '', everything: '', warning: null, never: null, measuring: false, note: tx(`${K}.backupContentsNeedsRestart`) };
105
+ if (!reading || reading.state === 'loading') return { available: false, rows: [], total: '', everything: '', warning: null, never: null, measuring: false, note: null };
106
+ if (reading.state !== 'ready') {
107
+ return { available: false, rows: [], total: '', everything: '', warning: null, never: null, measuring: false, note: tx(`${K}.backupContentsUnreadable`, { message: reading.message || '' }) };
108
+ }
109
+ const rows = reading.groups.map((group) => {
110
+ const copy = GROUP_COPY[group.id];
111
+ const measured = group.bytes != null;
112
+ return {
113
+ id: group.id,
114
+ label: copy ? tx(copy.label) : group.id,
115
+ help: copy ? tx(copy.help) : '',
116
+ kind: group.kind,
117
+ kindLabel: KIND_COPY[group.kind] ? tx(KIND_COPY[group.kind]) : '',
118
+ enabled: group.enabled,
119
+ size: !measured ? '' : group.files === 0 ? tx(`${K}.backupGroupEmpty`)
120
+ : tx(`${K}.backupGroupSize`, { size: formatContentsSize(group.bytes), archive: formatContentsSize(group.archiveBytes) }),
121
+ busy: saving === group.id,
122
+ };
123
+ });
124
+ const selected = reading.totals?.selected;
125
+ const everything = reading.totals?.everything;
126
+ const off = reading.irreplaceableOff.map(id => backupGroupLabel(id, tx));
127
+ let note = null;
128
+ if (notice?.kind === 'save') note = tx(`${K}.backupContentsSaveFailed`, { message: notice.message });
129
+ else if (reading.estimate.state === 'failed') note = tx(`${K}.backupContentsMeasureFailed`, { message: reading.estimate.error || '' });
130
+ return {
131
+ available: true,
132
+ rows,
133
+ total: selected ? tx(`${K}.backupContentsTotal`, { archive: formatContentsSize(selected.archiveBytes), size: formatContentsSize(selected.bytes), files: selected.files }) : '',
134
+ everything: selected && everything && everything.bytes > selected.bytes ? tx(`${K}.backupContentsEverything`, { archive: formatContentsSize(everything.archiveBytes) }) : '',
135
+ warning: off.length ? tx(`${K}.backupContentsWarning`, { groups: off.join(', ') }) : null,
136
+ never: reading.never ? tx(`${K}.backupContentsNever`, { size: formatContentsSize(reading.never.bytes) }) : null,
137
+ measuring: reading.estimate.state === 'measuring',
138
+ note,
139
+ };
140
+ }
141
+
142
+ /**
143
+ * What a backup holds, for the restore dialog, from the server's reading of its manifest (`contents` of POST
144
+ * /api/system/restore/preview: { recorded, included, excluded, complete, legacy }). →
145
+ * contains the groups in it, by name ('' when none is known)
146
+ * missing the groups it does not contain, by name: a restore leaves them as they are ('' when it holds all)
147
+ * stateOnly a pre-update snapshot: state without generated media
148
+ * null when the server said nothing about groups (a server from before).
149
+ */
150
+ export function describeRestoreContents(contents, { tx }) {
151
+ if (!contents || typeof contents !== 'object' || !Array.isArray(contents.included)) return null;
152
+ const names = (list) => (Array.isArray(list) ? list : []).filter(id => typeof id === 'string').map(id => backupGroupLabel(id, tx)).join(', ');
153
+ const contains = names(contents.included);
154
+ const missing = contents.complete === true ? '' : names(contents.excluded);
155
+ return {
156
+ contains: contains ? tx(`${K}.restoreContains`, { groups: contains }) : '',
157
+ missing: missing ? tx(`${K}.restoreNotContained`, { groups: missing }) : '',
158
+ stateOnly: contents.legacy === 'state-only' ? tx(`${K}.restoreStateOnly`) : '',
159
+ };
160
+ }
161
+
162
+ /**
163
+ * The list's behaviour, without a DOM. `render(model)` is called with `{ reading, notice, saving }` after every change.
164
+ * @param {object} o
165
+ * @param {typeof fetch} o.fetch
166
+ * @param {(model: object) => void} o.render
167
+ * @param {(ms: number) => Promise<void>} [o.wait] the pause between two looks at a running measurement
168
+ * @param {number} [o.pollMs]
169
+ * @param {number} [o.maxPolls] a measurement that long is no longer followed
170
+ * @param {() => boolean} [o.alive] false once the list is gone
171
+ */
172
+ export function createBackupContentsController({
173
+ fetch, render, wait = (ms) => new Promise((done) => setTimeout(done, ms)), pollMs = 1000, maxPolls = 180, alive = () => true,
174
+ } = {}) {
175
+ let reading = { state: 'loading' };
176
+ let notice = null;
177
+ let saving = null;
178
+ let following = false;
179
+
180
+ const show = () => { try { render({ reading, notice, saving }); } catch { /* a list that cannot be drawn changes nothing here */ } };
181
+
182
+ async function ask(method, url, body) {
183
+ try {
184
+ const init = { method };
185
+ if (body !== undefined) { init.headers = { 'Content-Type': 'application/json' }; init.body = JSON.stringify(body); }
186
+ const res = await fetch(url, init);
187
+ let json = null;
188
+ try { json = await res.json(); } catch { json = null; }
189
+ return readBackupContentsResponse({ status: res.status, body: json });
190
+ } catch (error) {
191
+ return readBackupContentsResponse({ error });
192
+ }
193
+ }
194
+
195
+ const measuring = () => reading.state === 'ready' && reading.estimate.state === 'measuring';
196
+
197
+ // Ask again while the server measures. A look that fails keeps what was known.
198
+ async function follow() {
199
+ if (following) return;
200
+ following = true;
201
+ try {
202
+ for (let polls = 0; measuring() && alive() && polls < maxPolls; polls++) {
203
+ await wait(pollMs);
204
+ if (saving) continue; // the answer to the switch under way is the newer state
205
+ const next = await ask('GET', BACKUP_CONTENTS_URL);
206
+ if (next.state === 'ready' && !saving) reading = next;
207
+ show();
208
+ }
209
+ } finally { following = false; }
210
+ }
211
+
212
+ async function load({ refresh = false } = {}) {
213
+ const next = await ask('GET', refresh ? `${BACKUP_CONTENTS_URL}?refresh=1` : BACKUP_CONTENTS_URL);
214
+ // A refresh that fails keeps the list that was there.
215
+ if (next.state === 'ready' || reading.state !== 'ready') reading = next;
216
+ show();
217
+ if (measuring()) await follow();
218
+ }
219
+
220
+ /** Switch one group. The switch shows the choice at once; a refusal puts it back and says why. */
221
+ async function toggle(id, enabled) {
222
+ if (reading.state !== 'ready' || saving) { show(); return false; }
223
+ const before = reading;
224
+ saving = id;
225
+ notice = null;
226
+ reading = { ...reading, groups: reading.groups.map(group => (group.id === id ? { ...group, enabled: !!enabled } : group)) };
227
+ show();
228
+ const next = await ask('PUT', BACKUP_CONTENTS_URL, { groups: { [id]: !!enabled } });
229
+ saving = null;
230
+ if (next.state === 'ready') reading = next;
231
+ else {
232
+ reading = before;
233
+ notice = { kind: 'save', message: next.state === 'old-server' ? 'HTTP 404' : next.message || '' };
234
+ }
235
+ show();
236
+ if (measuring()) follow();
237
+ return next.state === 'ready';
238
+ }
239
+
240
+ return { load, toggle, refresh: () => load({ refresh: true }), model: () => ({ reading, notice, saving }) };
241
+ }