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
@@ -26,8 +26,11 @@ import { closeMenu, isMenuOpen, openMenu } from './asst-menu.js';
26
26
  import { decorateControlHead } from './asst-control.js';
27
27
  import { accountSummary } from '../account-view.js';
28
28
  import { accountUsageText, autoAccountLabel } from '../account-usage.js';
29
+ import { registerLaunchPrefetch } from '../launch-prefetch.js';
30
+ import { createLazyModule } from '../lazy-module.js';
29
31
  import {
30
32
  DEFAULT_ROUTE_MODE,
33
+ displayProvider,
31
34
  fmtConfidence,
32
35
  modelShortName,
33
36
  normalizeBrain,
@@ -89,6 +92,40 @@ function tf(t) {
89
92
  };
90
93
  }
91
94
 
95
+ /**
96
+ * A task class in the user's language, keyed by its id (`assistant.routes.taskClass.<id>`); the server's
97
+ * label (English) is the fallback. `lower` is the sentence form.
98
+ */
99
+ export function routeClassLabel(taskClass, serverLabel, t, { lower = false } = {}) {
100
+ const tr = tf(t);
101
+ const id = str(taskClass);
102
+ const base = str(serverLabel) || humanizeClass(id);
103
+ const label = id ? tr(`assistant.routes.taskClass.${id}`, base) : base;
104
+ return lower ? label.toLowerCase() : label;
105
+ }
106
+
107
+ /**
108
+ * An effort id in the user's language (`assistant.routes.effortWord.<id>`), for display only: the id that is
109
+ * sent back to the server never changes. A locale that only repeats the id (English), or has no key, and an
110
+ * id nothing names (an OpenCode variant) keep `fallback` (default: the card's own word, "none" → "off").
111
+ */
112
+ export function routeEffortLabel(effort, t, fallback) {
113
+ const id = str(effort);
114
+ const raw = routeEffortWord(id);
115
+ const base = fallback == null ? raw : fallback;
116
+ if (!id) return base;
117
+ const v = tf(t)(`assistant.routes.effortWord.${id.toLowerCase()}`, '');
118
+ return v && v !== raw ? v : base;
119
+ }
120
+
121
+ /** A row's title with its trailing effort word in the user's language (the stored title stays English). */
122
+ export function routeTitleLocalized(o, t) {
123
+ const title = str(o?.title);
124
+ if (!o?.titleEffort || !o?.effort) return title;
125
+ const word = routeEffortLabel(o.effort, t);
126
+ return word === routeEffortWord(o.effort) ? title : `${routeTitleWithoutEffort(title, o.effort)} · ${word}`;
127
+ }
128
+
92
129
  function humanizeClass(value) {
93
130
  const s = str(value).replace(/[_-]+/g, ' ');
94
131
  return s ? s[0].toUpperCase() + s.slice(1) : 'General';
@@ -197,6 +234,7 @@ export function normalizeRouteRequest(packet) {
197
234
  needsVision: req.needsVision === true,
198
235
  // Image / video creation: the medium the model must generate ('image' | 'video'), always on a worker.
199
236
  requires: req.requires === 'image' || req.requires === 'video' ? req.requires : null,
237
+ needsHost: req.needsHost === true || req.sides?.dispatch?.code === 'host_only',
200
238
  dispatchOnly: req.dispatchOnly === true,
201
239
  // Design: only models that can see.
202
240
  visionOnly: req.visionOnly === true,
@@ -359,6 +397,7 @@ export function routeOptions(n, { brainLabel = '', t = null } = {}) {
359
397
  }
360
398
  const kept = [];
361
399
  for (const o of options) {
400
+ if (n.needsHost && o.kind !== 'direct') continue;
362
401
  const twin = kept.find(k => sameRouteTarget(k, o));
363
402
  if (twin) {
364
403
  if (defaultId === o.id) defaultId = twin.id;
@@ -426,10 +465,13 @@ export function routeCardSides(n, options, { t = null } = {}) {
426
465
  const usable = list.filter((o) => !o.disabled);
427
466
  const said = server?.[kind] || null;
428
467
  const out = { kind, options: list, available: usable.length > 0, reason: null, code: null, needsPick: false, defaultId: null };
468
+ if (kind === 'dispatch' && n?.needsHost) {
469
+ return { ...out, options: [], available: false, code: 'host_only', reason: tr('assistant.routes.side.hostOnly', 'This task requires host access in this conversation.') };
470
+ }
429
471
  out.defaultId = (usable.find((o) => o.id === n?.defaultOptionId) || usable.find((o) => o.id === n?.defaults?.[kind]) || usable.find((o) => o.selected) || usable[0])?.id || null;
430
472
  if (out.available) return out;
431
473
  if (kind === 'direct' && n?.dispatchOnly) {
432
- return { ...out, code: 'worker_only', reason: tr('assistant.routes.side.workerOnly', '{taskClass} always runs on a worker.', { taskClass: n.taskClassLabel || humanizeClass(n.taskClass) }) };
474
+ return { ...out, code: 'worker_only', reason: tr('assistant.routes.side.workerOnly', '{taskClass} always runs on a worker.', { taskClass: routeClassLabel(n.taskClass, n.taskClassLabel, t) }) };
433
475
  }
434
476
  if (kind === 'direct' && (said?.code === 'account_worker' || arr(options).some((o) => o.kind === 'dispatch' && o.accountKind === 'direct'))) {
435
477
  return { ...out, code: 'account_worker', reason: tr('assistant.routes.side.accountWorker', "This conversation's account can't take it now, so it runs on a worker.") };
@@ -448,7 +490,7 @@ export function routeCardSides(n, options, { t = null } = {}) {
448
490
  const chosen = arr(options).find((o) => o.selected && !o.disabled);
449
491
  let initial = chosen ? (chosen.kind === 'direct' ? 'direct' : 'dispatch') : null;
450
492
  if (!initial || !sides[initial].available) initial = sides.direct.available && sides.direct.defaultId ? 'direct' : 'dispatch';
451
- return { initial, sides };
493
+ return { initial: n?.needsHost ? 'direct' : initial, sides };
452
494
  }
453
495
 
454
496
  /** control_response payload for a route card. `decline:true` is the Cancel answer. */
@@ -548,7 +590,7 @@ export function routeLineParts(route, phase = 'decided', { brainLabel = '', t =
548
590
  const tr = tf(t);
549
591
  const r = obj(route) || {};
550
592
  const target = obj(r.target);
551
- const cls = firstStr(r.taskClassLabel, r.taskClass) || tr('assistant.routes.task', 'task');
593
+ const cls = (r.taskClass ? routeClassLabel(r.taskClass, firstStr(r.taskClassLabel, r.taskClass), t) : firstStr(r.taskClassLabel)) || tr('assistant.routes.task', 'task');
552
594
  const kind = target ? (str(target.kind) || 'direct') : '';
553
595
  const effort = target ? str(target.effort) : '';
554
596
  const confidence = fmtConfidence(r.confidence);
@@ -560,6 +602,7 @@ export function routeLineParts(route, phase = 'decided', { brainLabel = '', t =
560
602
  state = str(r.needs) === 'vision' ? tr('assistant.routes.reason.noSeeingModel', 'no model can see images') : tr('assistant.routes.reason.noCapableModel', 'no model can make this');
561
603
  }
562
604
  else if (str(r.reasonCode) === 'budget_exhausted') state = routeBudgetReason({ dry: r.dry }, t);
605
+ else if (str(r.reasonCode) === 'BUDGET_UNPRICED') state = routeBudgetReason({ provider: r.provider, unpriced: true }, t);
563
606
  else if (phase === 'declined') state = tr('assistant.routes.state.declined', 'declined');
564
607
  else if (phase === 'cancelled') state = tr('assistant.routes.state.cancelled', 'cancelled');
565
608
  let decided = '';
@@ -576,7 +619,7 @@ export function routeLineParts(route, phase = 'decided', { brainLabel = '', t =
576
619
  if (r.plannedSplit?.workers) meta.push(tf(t)('assistant.routes.splitWorkers', '{count} workers planned', { count: r.plannedSplit.workers }));
577
620
  const accountLabel = routeDisplayAccount(target, t);
578
621
  if (accountLabel) meta.push(accountLabel);
579
- if (effort && effort !== 'off') meta.push(routeEffortWord(effort));
622
+ if (effort && effort !== 'off') meta.push(routeEffortLabel(effort, t));
580
623
  if (confidence) meta.push(confidence);
581
624
  return {
582
625
  taskClass: cls,
@@ -607,6 +650,11 @@ function correctionText(c, tr) {
607
650
  }
608
651
  if (c.reason === 'remembered_route') return tr('assistant.routes.correction.remembered', 'your saved route {to} replaced {from}', { to: str(c.to), from: str(c.from) });
609
652
  if (c.reason === 'remembered_disabled') return tr('assistant.routes.correction.rememberedDisabled', 'saved route {from} is disabled, kept the pick', { from: str(c.from) });
653
+ if (c.reason === 'remembered_host') return tr('assistant.routes.correction.rememberedHost', 'Skipped the saved route {from} because this task requires host access.', { from: str(c.from) });
654
+ if (c.reason === 'superseded_run_active' && arr(c.runs).length) {
655
+ const runs = c.runs.map(r => [str(r?.runId), str(r?.title)].filter(Boolean).join(' — ')).filter(Boolean).join(', ');
656
+ return tr('assistant.routes.correction.supersededRunActive', 'Workers from the previous dispatch are still active ({runs}).', { runs });
657
+ }
610
658
  // A "here" pick that runs on a worker: another account, or another provider than this conversation's.
611
659
  if (c.reason === 'account_worker') return tr('assistant.routes.correction.accountWorker', '{to}: runs on a worker, because this conversation belongs to another account', { to: str(c.to) });
612
660
  if (c.reason === 'other_provider' && c.provider) return tr('assistant.routes.correction.otherProvider', "{provider} is not this conversation's provider, so it runs on a worker", { provider: providerLabel(c.provider) });
@@ -718,9 +766,10 @@ export function createRouteLine(route, opts = {}) {
718
766
  arrow.hidden = !p.targetLabel && !p.pending && !p.kindLabel;
719
767
  kindEl.textContent = p.kindLabel;
720
768
  kindEl.hidden = !p.kindLabel;
721
- iconEl.innerHTML = p.targetLabel ? providerIconHtml(p.provider, opts) : '';
769
+ const brand = displayProvider(current.route?.target) || p.provider;
770
+ iconEl.innerHTML = p.targetLabel ? providerIconHtml(brand, opts) : '';
722
771
  iconEl.hidden = !iconEl.innerHTML;
723
- if (p.provider) iconEl.style.color = providerColor(p.provider); else iconEl.style.color = '';
772
+ if (p.provider) iconEl.style.color = providerColor(brand); else iconEl.style.color = '';
724
773
  targetEl.textContent = p.targetLabel;
725
774
  targetEl.hidden = !p.targetLabel;
726
775
  metaEl.textContent = p.meta.length ? `· ${p.meta.join(' · ')}` : '';
@@ -903,7 +952,7 @@ export function renderRouteCard(container, input, hooks = {}) {
903
952
  card.dataset.requestId = n.requestId;
904
953
  card.dataset.routeId = n.routeId;
905
954
  card.setAttribute('role', 'group');
906
- const heading = tr('assistant.routes.cardTitle', 'Route this request · {taskClass}', { taskClass: n.taskClassLabel });
955
+ const heading = tr('assistant.routes.cardTitle', 'Route this request · {taskClass}', { taskClass: routeClassLabel(n.taskClass, n.taskClassLabel, hooks.t) });
907
956
  card.setAttribute('aria-label', heading);
908
957
 
909
958
  const head = el('div', 'asst-control-head');
@@ -933,8 +982,9 @@ export function renderRouteCard(container, input, hooks = {}) {
933
982
  const sidesEl = el('div', 'asst-route-sides');
934
983
  sidesEl.setAttribute('role', 'radiogroup');
935
984
  sidesEl.setAttribute('aria-label', tr('assistant.routes.side.label', 'Where it runs'));
985
+ const visibleSides = n.needsHost ? ['direct'] : ROUTE_SIDES;
936
986
  const sideBtns = {};
937
- for (const kind of ROUTE_SIDES) {
987
+ for (const kind of visibleSides) {
938
988
  const btn = el('button', 'asst-route-side', kind === 'direct' ? tr('assistant.routes.side.here', 'Here') : tr('assistant.routes.side.dispatch', 'Dispatch'));
939
989
  btn.type = 'button';
940
990
  btn.dataset.side = kind;
@@ -953,6 +1003,7 @@ export function renderRouteCard(container, input, hooks = {}) {
953
1003
  card.appendChild(list);
954
1004
 
955
1005
  function optionRow(o) {
1006
+ const brand = displayProvider(o);
956
1007
  const row = el('div', 'asst-route-option');
957
1008
  row.setAttribute('role', 'radio');
958
1009
  row.dataset.optionId = o.id;
@@ -960,17 +1011,17 @@ export function renderRouteCard(container, input, hooks = {}) {
960
1011
  row.setAttribute('aria-disabled', o.disabled ? 'true' : 'false');
961
1012
  row.tabIndex = -1;
962
1013
  const kindWord = o.kind && o.kind !== 'direct' ? routeKindWord(o.kind, hooks.t) : '';
963
- const sub = [kindWord, o.agentRef, routeDisplayAccount(o, hooks.t), o.effort && o.effort !== 'off' && !o.titleEffort ? routeEffortWord(o.effort) : '', o.price ? priceText(o.price) : '', o.vision ? tr('assistant.brain.vision', 'vision') : '', o.reason].filter(Boolean).join(' · ');
1014
+ const sub = [kindWord, o.agentRef, routeDisplayAccount(o, hooks.t), o.effort && o.effort !== 'off' && !o.titleEffort ? routeEffortLabel(o.effort, hooks.t) : '', o.price ? priceText(o.price) : '', o.vision ? tr('assistant.brain.vision', 'vision') : '', o.reason].filter(Boolean).join(' · ');
964
1015
  row.innerHTML = `
965
1016
  <span class="asst-route-num" aria-hidden="true">${esc(o.number)}</span>
966
- <span class="asst-route-opt-icon asst-icon" aria-hidden="true"${o.provider ? ` style="color:${esc(providerColor(o.provider))}"` : ''}>${providerIconHtml(o.provider, hooks)}</span>
1017
+ <span class="asst-route-opt-icon asst-icon" aria-hidden="true"${o.provider ? ` style="color:${esc(providerColor(brand))}"` : ''}>${providerIconHtml(brand, hooks)}</span>
967
1018
  <span class="asst-route-opt-main">
968
1019
  <span class="asst-route-opt-title"></span>
969
1020
  ${sub ? '<span class="asst-route-opt-sub"></span>' : ''}
970
1021
  ${o.warning || (o.disabled && o.disabledReason) ? '<span class="asst-route-opt-warn"></span>' : ''}
971
1022
  </span>
972
1023
  ${o.badgeText ? `<span class="asst-route-badge" data-badge="${esc(o.badge || '')}"></span>` : ''}`;
973
- row.querySelector('.asst-route-opt-title').textContent = o.title;
1024
+ row.querySelector('.asst-route-opt-title').textContent = routeTitleLocalized(o, hooks.t);
974
1025
  if (sub) row.querySelector('.asst-route-opt-sub').textContent = sub;
975
1026
  const warn = row.querySelector('.asst-route-opt-warn');
976
1027
  if (warn) warn.textContent = o.accountError ? routeAccountError(o.accountError, hooks.t) : o.disabled && o.disabledReason ? o.disabledReason : o.warning;
@@ -1013,7 +1064,7 @@ export function renderRouteCard(container, input, hooks = {}) {
1013
1064
  /** The switch, its note (why the other side is unavailable, what a worker side still needs, else what the side means) and the Run label. */
1014
1065
  function syncSides() {
1015
1066
  card.dataset.side = state.side;
1016
- for (const kind of ROUTE_SIDES) {
1067
+ for (const kind of visibleSides) {
1017
1068
  const btn = sideBtns[kind];
1018
1069
  const side = view.sides[kind];
1019
1070
  const on = state.side === kind;
@@ -1078,11 +1129,15 @@ export function renderRouteCard(container, input, hooks = {}) {
1078
1129
  }
1079
1130
  function syncFields() {
1080
1131
  const target = selected();
1081
- setFieldLabel(otherBtn, target ? routeTargetLabel(target) : tr('assistant.routes.other', 'Other model…'));
1132
+ // The router's "Do it here with ‹model›" label reads in the user's language, like the list rows.
1133
+ const targetText = !target ? '' : target.kind === 'direct' && /^do it here with\s+/i.test(str(target.label))
1134
+ ? tr('assistant.routes.doHere', 'Do it here with {model}', { model: routeHereModelLabel(target) || modelShortName(target.model) || target.id })
1135
+ : routeTargetLabel(target);
1136
+ setFieldLabel(otherBtn, target ? targetText : tr('assistant.routes.other', 'Other model…'));
1082
1137
  otherBtn.setAttribute('aria-label', tr('assistant.brain.model', 'Model'));
1083
1138
  otherBtn.disabled = busy();
1084
1139
  setFieldLabel(effortBtn, !target?.effort ? tr('assistant.routes.editorEffortAuto', 'Auto')
1085
- : target.effort === ROUTE_EFFORT_OFF ? tr('assistant.routes.editorEffortOff', 'Off') : target.effort);
1140
+ : target.effort === ROUTE_EFFORT_OFF ? tr('assistant.routes.editorEffortOff', 'Off') : routeEffortLabel(target.effort, hooks.t, target.effort));
1086
1141
  effortBtn.setAttribute('aria-label', tr('assistant.brain.effort', 'Thinking effort'));
1087
1142
  setFieldLabel(accountBtn, routeDisplayAccount(target, hooks.t) || tr('assistant.routes.account.workersDefault', 'Workers default'));
1088
1143
  accountBtn.setAttribute('aria-label', tr('assistant.brain.account', 'Account profile'));
@@ -1097,7 +1152,7 @@ export function renderRouteCard(container, input, hooks = {}) {
1097
1152
  const choices = routeEffortChoices(target.provider, catalogModelRow(target.provider, target.model));
1098
1153
  openMenu(effortBtn, { title: tr('assistant.brain.effort', 'Thinking effort'), placement: 'auto', items: [
1099
1154
  { kind: 'radio', label: tr('assistant.routes.editorEffortAuto', 'Auto'), selected: !target.effort, onSelect: () => editTarget({ effort: null }) },
1100
- ...choices.map(e => ({ kind: 'radio', label: e.off ? tr('assistant.routes.editorEffortOff', 'Off') : e.label, selected: target.effort === e.id, onSelect: () => editTarget({ effort: e.id }) })),
1155
+ ...choices.map(e => ({ kind: 'radio', label: e.off ? tr('assistant.routes.editorEffortOff', 'Off') : routeEffortLabel(e.id, hooks.t, e.label), selected: target.effort === e.id, onSelect: () => editTarget({ effort: e.id }) })),
1101
1156
  ] });
1102
1157
  });
1103
1158
  accountBtn.addEventListener('click', async () => {
@@ -1176,7 +1231,9 @@ export function renderRouteCard(container, input, hooks = {}) {
1176
1231
  rememberInput.type = 'checkbox';
1177
1232
  rememberInput.addEventListener('change', () => { state.remember = rememberInput.checked; });
1178
1233
  // `remember.label` is the task-class label ("Code"), not a sentence.
1179
- const text = tr('assistant.routes.rememberFor', 'Use this choice for {taskClass} tasks', { taskClass: (n.remember.label || n.taskClassLabel).toLowerCase() });
1234
+ // A key per class carries the whole phrase so the plural noun agrees ("tarefas rápidas"); the generic one is the fallback.
1235
+ const rememberClass = n.remember.taskClass || n.taskClass;
1236
+ const text = tr(`assistant.routes.rememberForClass.${rememberClass}`, '') || tr('assistant.routes.rememberFor', 'Use this choice for {taskClass} tasks', { taskClass: routeClassLabel(rememberClass, n.remember.label || n.taskClassLabel, hooks.t, { lower: true }) });
1180
1237
  label.append(rememberInput, el('span', null, text));
1181
1238
  if (n.remember.current) label.appendChild(el('span', 'asst-route-remember-current', tr('assistant.routes.rememberCurrent', 'now: {current}', { current: n.remember.current })));
1182
1239
  card.appendChild(label);
@@ -1188,7 +1245,7 @@ export function renderRouteCard(container, input, hooks = {}) {
1188
1245
  card.appendChild(error);
1189
1246
 
1190
1247
  const actions = el('div', 'asst-control-actions');
1191
- const cancelBtn = el('button', 'asst-btn asst-btn-secondary asst-route-cancel', n.decline.label || tr('common.cancel', 'Cancel'));
1248
+ const cancelBtn = el('button', 'asst-btn asst-btn-secondary asst-route-cancel', (n.decline.label && n.decline.label !== 'Cancel' ? n.decline.label : tr('common.cancel', 'Cancel')));
1192
1249
  cancelBtn.type = 'button';
1193
1250
  // When the server does not accept a decline, the card can only be answered.
1194
1251
  cancelBtn.hidden = !n.decline.allowed;
@@ -1388,11 +1445,13 @@ export function renderRouteCard(container, input, hooks = {}) {
1388
1445
  return collapse(phase, route);
1389
1446
  },
1390
1447
  /** ROUTE_INVALID: keep (or re-open) the card with the message. */
1391
- fail(message) {
1448
+ fail(message, code) {
1392
1449
  clearTimers();
1393
1450
  restore();
1394
1451
  setPending(false, '');
1395
- error.textContent = message || tr('assistant.routes.invalid', 'That route is not available. Pick another option.');
1452
+ error.textContent = n.needsHost && code === 'ROUTE_IS_DIRECT'
1453
+ ? view.sides.dispatch.reason
1454
+ : message || tr('assistant.routes.invalid', 'That route is not available. Pick another option.');
1396
1455
  error.hidden = false;
1397
1456
  if (expires) { tick(); if (!state.expired) state.timer = setInterval(tick, 1000); }
1398
1457
  entry.focus();
@@ -1403,8 +1462,28 @@ export function renderRouteCard(container, input, hooks = {}) {
1403
1462
  }
1404
1463
 
1405
1464
  // ── Routes editor (draft, modes, task choices) ───────────────────────────────
1406
- // Its model lists still come only through asst-route-models.js.
1407
- export { openRoutesEditor } from './asst-routes-editor.js';
1465
+ // Its model lists still come only through asst-route-models.js. The module loads in an idle moment after the page
1466
+ // is shown or at the first open, whichever comes first (lazy-module.js), so the page does not wait for it at boot.
1467
+ // A browser keeps a failed module address failed for the life of the page (a server restart can refuse the idle
1468
+ // load), so a later attempt asks under a new address. A failed load never ran, so there is still one editor.
1469
+ let routesEditorAttempts = 0;
1470
+ const routesEditorModule = createLazyModule(() => {
1471
+ const attempt = routesEditorAttempts++;
1472
+ return attempt ? import(`./asst-routes-editor.js?retry=${attempt}`) : import('./asst-routes-editor.js');
1473
+ }, { name: 'Routes editor' });
1474
+ if (typeof document !== 'undefined') registerLaunchPrefetch('assistant-routes-editor', () => routesEditorModule.load(), { order: 16 });
1475
+
1476
+ export function openRoutesEditor(hooks = {}) {
1477
+ const loaded = routesEditorModule.module;
1478
+ if (loaded) return loaded.openRoutesEditor(hooks);
1479
+ // Focus can move during the load: the control that opened the editor is the one it gives focus back to.
1480
+ const opened = { ...hooks, returnTo: hooks.returnTo ?? globalThis.document?.activeElement };
1481
+ return routesEditorModule.load().then(mod => mod.openRoutesEditor(opened), (err) => {
1482
+ const text = hooks.t?.('assistant.routes.loadFailed');
1483
+ hooks.onToast?.(typeof text === 'string' && text !== 'assistant.routes.loadFailed' ? text : 'Could not load model routes');
1484
+ throw err;
1485
+ });
1486
+ }
1408
1487
 
1409
1488
  // ── Models manager (Assistant → Models…) ───────────────────────────────────
1410
1489
 
@@ -96,7 +96,7 @@ export async function openRoutesEditor(hooks = {}) {
96
96
  if (editor) { editor.focus(); return editor; }
97
97
  const tr = translator(hooks.t);
98
98
  const id = `asst-routes-${++uid}`;
99
- const returnTo = document.activeElement;
99
+ const returnTo = hooks.returnTo ?? document.activeElement;
100
100
  const overlay = el('div', 'asst-modal-overlay asst-routes-overlay');
101
101
  overlay.setAttribute('role', 'dialog'); overlay.setAttribute('aria-modal', 'true'); overlay.setAttribute('aria-labelledby', `${id}-title`);
102
102
  const modal = el('div', 'asst-modal asst-routes-modal');
@@ -0,0 +1,200 @@
1
+ // ─────────────────────────────────────────────────────────────────────────────
2
+ // SynaBun Assistant — the shell commands of an OpenCode brain (no DOM, no socket)
3
+ //
4
+ // The runtime tells a panel which commands the brain's tool calls started and how
5
+ // they ended (`assistant:shell`, `assistant:shells`). What a command printed is
6
+ // never in those packets: it is read in pages over REST, only while a terminal
7
+ // block shows that command, by the same follower and terminal buffer as the
8
+ // OpenCode side panel (ocp-v2-shell-logic.js). Everything here is display data:
9
+ // nothing of it goes to the model, the transcript, a memory or a meter.
10
+ // ─────────────────────────────────────────────────────────────────────────────
11
+
12
+ import { createShellFollower, formatBytes, shellCardState } from '../ocp-v2/ocp-v2-shell-logic.js';
13
+
14
+ /** How many finished commands keep their read output once no block shows them (the next look reads it again). */
15
+ export const SHELL_KEPT_FINISHED = 12;
16
+
17
+ const GONE_VIEW = Object.freeze({ text: '', from: 0, size: 0, done: true, gone: true, error: '', full: false, capped: false, partial: false });
18
+
19
+ /**
20
+ * createShellTracker({ read })
21
+ * read({ shellId, cursor, tail, limit }) → { status, data: { output, cursor, size, from } } or { ok: false, status, error }
22
+ * apply / applyList take what the runtime says; open(id) + subscribe(id, fn) follow one command for as long as a
23
+ * block shows it; onChange(fn) hears that a command's state changed.
24
+ */
25
+ export function createShellTracker({ read, setTimer, clearTimer, kept = SHELL_KEPT_FINISHED } = {}) {
26
+ const shells = new Map(); // shellId → the runtime's view of it
27
+ const byCall = new Map(); // the tool call's id → shellId
28
+ const entries = new Map(); // shellId → { follower, view, usedAt }
29
+ const listeners = new Map(); // shellId → Set of what draws it
30
+ const places = new Map(); // shellId → { follow, top }: where the reader left its block
31
+ const changes = new Set();
32
+ let clock = 0;
33
+ let destroyed = false;
34
+
35
+ const tell = (shellId) => {
36
+ for (const fn of [...(listeners.get(shellId) || [])]) { try { fn(); } catch (err) { console.warn('[asst-shell] draw failed', err); } }
37
+ };
38
+ const changed = (shell) => {
39
+ for (const fn of [...changes]) { try { fn(shell); } catch (err) { console.warn('[asst-shell] update failed', err); } }
40
+ };
41
+
42
+ // Stop removes a command from OpenCode, so its next read is a 404. What was read up to then is what it printed
43
+ // before it was stopped: nothing to apologise for, unless the start of a long output is out of reach.
44
+ const settledView = (shellId, view) => (view.gone && view.text && !view.partial && shells.get(shellId)?.status === 'killed'
45
+ ? { ...view, gone: false, done: true }
46
+ : view);
47
+
48
+ function dropEntry(shellId) {
49
+ entries.get(shellId)?.follower?.stop();
50
+ entries.delete(shellId);
51
+ }
52
+
53
+ /** Finished commands nobody looks at keep their text up to `kept`; the oldest goes first. */
54
+ function evict() {
55
+ const idle = [...entries].filter(([id]) => !listeners.get(id)?.size).sort((a, b) => a[1].usedAt - b[1].usedAt);
56
+ while (idle.length > kept) {
57
+ const [id] = idle.shift();
58
+ dropEntry(id);
59
+ places.delete(id);
60
+ }
61
+ }
62
+
63
+ function apply(shell) {
64
+ if (destroyed || !shell?.id) return;
65
+ const known = shells.get(shell.id);
66
+ // Named again after it was lost (a brain that came back to its serve): it is read afresh.
67
+ if (known?.lost) dropEntry(shell.id);
68
+ shells.set(shell.id, shell);
69
+ if (shell.callID) byCall.set(shell.callID, shell.id);
70
+ if (shell.status !== 'running') entries.get(shell.id)?.follower?.poke();
71
+ tell(shell.id);
72
+ changed(shell);
73
+ }
74
+
75
+ /** The brain no longer has this command (it was replaced, or its serve ended). What was read stays on screen. */
76
+ function lose(shellId) {
77
+ const shell = shells.get(shellId);
78
+ if (!shell || shell.lost) return;
79
+ const next = { ...shell, lost: true, status: shell.status === 'running' ? 'killed' : shell.status };
80
+ shells.set(shellId, next);
81
+ const entry = entries.get(shellId);
82
+ if (entry) {
83
+ entry.follower?.stop();
84
+ entry.follower = null;
85
+ const view = entry.view;
86
+ // Read to its end, the text on screen is the whole output: nothing is missing from it.
87
+ if (!view) entry.view = { ...GONE_VIEW };
88
+ else if (!view.done || view.partial) entry.view = { ...view, done: true, gone: true };
89
+ }
90
+ tell(shellId);
91
+ changed(next);
92
+ }
93
+
94
+ /** The whole list as the runtime knows it now: a command it no longer names is gone. */
95
+ function applyList(list) {
96
+ if (destroyed) return;
97
+ const named = new Set();
98
+ for (const shell of Array.isArray(list) ? list : []) {
99
+ if (!shell?.id) continue;
100
+ named.add(shell.id);
101
+ apply(shell);
102
+ }
103
+ for (const id of [...shells.keys()]) if (!named.has(id)) lose(id);
104
+ }
105
+
106
+ /** Start reading a command for a block that shows it. */
107
+ function open(shellId) {
108
+ if (destroyed || !shells.has(shellId)) return;
109
+ let entry = entries.get(shellId);
110
+ if (!entry) {
111
+ entry = { follower: null, view: null, usedAt: 0 };
112
+ entries.set(shellId, entry);
113
+ if (shells.get(shellId).lost) entry.view = { ...GONE_VIEW };
114
+ else {
115
+ const mine = entry;
116
+ const options = {
117
+ api: { shellOutput: ({ shellId: id, cursor, tail, limit }) => read({ shellId: id, cursor, tail, limit }) },
118
+ sessionId: 'assistant', shellId,
119
+ isRunning: () => shells.get(shellId)?.status === 'running',
120
+ onUpdate: (view) => { if (entries.get(shellId) === mine) { mine.view = settledView(shellId, view); tell(shellId); } },
121
+ };
122
+ if (setTimer) options.setTimer = setTimer;
123
+ if (clearTimer) options.clearTimer = clearTimer;
124
+ entry.follower = createShellFollower(options);
125
+ entry.follower.start();
126
+ }
127
+ }
128
+ entry.usedAt = ++clock;
129
+ evict();
130
+ }
131
+
132
+ function subscribe(shellId, fn) {
133
+ let set = listeners.get(shellId);
134
+ if (!set) { set = new Set(); listeners.set(shellId, set); }
135
+ set.add(fn);
136
+ return () => {
137
+ set.delete(fn);
138
+ if (set.size) return;
139
+ listeners.delete(shellId);
140
+ // Nobody looks: nothing is polled. A command that ended and was read keeps its text for the next look.
141
+ const entry = entries.get(shellId);
142
+ if (entry?.follower && !entry.follower.isDone()) dropEntry(shellId);
143
+ evict();
144
+ };
145
+ }
146
+
147
+ return {
148
+ apply,
149
+ applyList,
150
+ open,
151
+ subscribe,
152
+ loadAll(shellId) { entries.get(shellId)?.follower?.loadAll(); },
153
+ forCall: (callId) => shells.get(byCall.get(callId)) || null,
154
+ shell: (shellId) => shells.get(shellId) || null,
155
+ view: (shellId) => entries.get(shellId)?.view || null,
156
+ placeOf(shellId) {
157
+ let place = places.get(shellId);
158
+ if (!place) { place = { follow: true, top: 0 }; places.set(shellId, place); }
159
+ return place;
160
+ },
161
+ onChange(fn) { changes.add(fn); return () => changes.delete(fn); },
162
+ /** For tests: which commands are being read now. */
163
+ reading: () => [...entries].filter(([, entry]) => entry.follower && !entry.follower.isDone()).map(([id]) => id),
164
+ destroy() {
165
+ destroyed = true;
166
+ for (const id of [...entries.keys()]) dropEntry(id);
167
+ listeners.clear();
168
+ changes.clear();
169
+ },
170
+ };
171
+ }
172
+
173
+ /** The word on a call's row for its command ('' when the call's own state says it). */
174
+ export function shellStateLabel(shell, t) {
175
+ if (!shell) return '';
176
+ if (shell.status === 'running') {
177
+ return shell.background ? t('assistant.rack.shell.background', 'in the background') : t('assistant.rack.shell.running', 'running');
178
+ }
179
+ if (shell.status === 'killed') return t('assistant.rack.shell.stopped', 'stopped');
180
+ if (shell.status === 'timeout') return t('assistant.rack.shell.timedOut', 'timed out');
181
+ if (typeof shell.exit === 'number') return t('assistant.rack.shell.exit', 'exit {code}', { code: shell.exit });
182
+ return '';
183
+ }
184
+
185
+ /** A command the model no longer waits for failed after its tool call had already answered. */
186
+ export function shellFailedLate(shell) {
187
+ return shellCardState(shell).status === 'error';
188
+ }
189
+
190
+ /** The line above a terminal block when it does not show everything: '' when it does. */
191
+ export function shellNoteText(view, t) {
192
+ if (!view) return '';
193
+ if (view.gone) return t('assistant.rack.shell.gone', 'OpenCode no longer keeps the output of this command.');
194
+ const shown = formatBytes(view.text.length);
195
+ const size = formatBytes(view.size);
196
+ if (view.capped) return t('assistant.rack.shell.capped', 'Showing the last {shown} of {size}: the whole output is too long to show here.', { shown, size });
197
+ if (view.partial) return t('assistant.rack.shell.partial', 'Showing the last {shown} of {size}.', { shown, size });
198
+ return '';
199
+ }
200
+
@@ -0,0 +1,111 @@
1
+ // ─────────────────────────────────────────────────────────────────────────────
2
+ // SynaBun Assistant — a shell call's live terminal block
3
+ //
4
+ // The block itself is the OpenCode panel's (ocp-v2-shell-block.js) in the rack's
5
+ // classes and words; the command's state and output come from the tracker
6
+ // (asst-shell-logic.js). A long test run must not cost the conversation
7
+ // anything: drawing is coalesced to one frame, and a block that is off screen or
8
+ // in a closed panel does no DOM work at all until it is seen again.
9
+ // ─────────────────────────────────────────────────────────────────────────────
10
+
11
+ import { createTerminalBlock } from '../ocp-v2/ocp-v2-shell-block.js';
12
+ import { shellNoteText } from './asst-shell-logic.js';
13
+
14
+ const SHOW_EVENT = 'asst-term-show';
15
+
16
+ const CLASSES = Object.freeze({
17
+ wrap: 'asst-term',
18
+ note: 'asst-term-note',
19
+ noteText: 'asst-term-note-text',
20
+ load: 'asst-tool-more asst-term-load',
21
+ out: 'asst-tool-section asst-term-out',
22
+ foot: 'asst-term-foot',
23
+ state: 'asst-term-state',
24
+ jump: 'asst-tool-more asst-term-jump',
25
+ copy: 'asst-copy asst-term-copy',
26
+ });
27
+
28
+ /**
29
+ * mountShellTerminal(tracker, shellId, { t, onDraw, onGone }) → { el, show(), dispose() }
30
+ * `onDraw`: the block was drawn (its height may have changed); `onGone`: OpenCode no longer has this output.
31
+ */
32
+ export function mountShellTerminal(tracker, shellId, { t, onDraw = () => {}, onGone = () => {} } = {}) {
33
+ let drawBlock = null;
34
+ let frame = 0;
35
+ let dirty = false;
36
+ let seen = true;
37
+ let disposed = false;
38
+ let wasGone = !!tracker.view(shellId)?.gone;
39
+ let wrap = null;
40
+
41
+ const flush = () => {
42
+ frame = 0;
43
+ if (disposed || !dirty || !seen || !wrap?.isConnected) return;
44
+ dirty = false;
45
+ drawBlock?.();
46
+ onDraw();
47
+ const gone = !!tracker.view(shellId)?.gone;
48
+ if (gone && !wasGone) { wasGone = true; onGone(); }
49
+ };
50
+ const request = () => {
51
+ dirty = true;
52
+ if (frame || !seen) return;
53
+ frame = requestAnimationFrame(flush);
54
+ };
55
+
56
+ tracker.open(shellId);
57
+ wrap = createTerminalBlock({
58
+ shellId,
59
+ place: tracker.placeOf(shellId),
60
+ showEvent: SHOW_EVENT,
61
+ read: () => ({ view: tracker.view(shellId), shell: tracker.shell(shellId) }),
62
+ // Told through `request` below, for as long as this mount lives (dispose ends it).
63
+ subscribe: (draw) => {
64
+ drawBlock = draw;
65
+ return () => {};
66
+ },
67
+ loadAll: () => tracker.loadAll(shellId),
68
+ classes: CLASSES,
69
+ words: {
70
+ load: t('assistant.rack.shell.loadFull', 'Load full output'),
71
+ loading: t('assistant.rack.shell.loading', 'Loading…'),
72
+ jump: t('assistant.rack.shell.jump', 'Jump to latest'),
73
+ copy: t('assistant.rack.shell.copy', 'Copy output'),
74
+ copied: t('assistant.rack.shell.copied', 'Copied'),
75
+ label: t('assistant.rack.shell.label', 'Command output'),
76
+ noOutputYet: t('assistant.rack.shell.noOutputYet', 'No output yet'),
77
+ noOutput: t('assistant.rack.shell.noOutput', 'No output'),
78
+ reading: t('assistant.rack.shell.reading', 'Reading the output…'),
79
+ running: t('assistant.rack.shell.runningNow', 'Running'),
80
+ note: (view) => shellNoteText(view, t),
81
+ },
82
+ });
83
+
84
+ // Not tied to being in the page: a row can be out of it for a moment while it is rebuilt.
85
+ const release = tracker.subscribe(shellId, request);
86
+ const watcher = typeof IntersectionObserver === 'function'
87
+ ? new IntersectionObserver((entries) => {
88
+ seen = entries[entries.length - 1].isIntersecting;
89
+ if (seen && dirty && !frame) frame = requestAnimationFrame(flush);
90
+ })
91
+ : null;
92
+ watcher?.observe(wrap);
93
+
94
+ return {
95
+ el: wrap,
96
+ /** The block is in the page again (a body rebuilt, a row opened): it measures itself and catches up. */
97
+ show() {
98
+ wrap.dispatchEvent(new Event(SHOW_EVENT));
99
+ request();
100
+ },
101
+ dispose() {
102
+ if (disposed) return;
103
+ disposed = true;
104
+ if (frame) cancelAnimationFrame(frame);
105
+ frame = 0;
106
+ watcher?.disconnect();
107
+ release();
108
+ wrap.remove();
109
+ },
110
+ };
111
+ }
@@ -30,7 +30,6 @@ import { brainLabel, readStoredBrain, restoredSessionName } from './asst-state.j
30
30
  import { closeMenu, isMenuOpen, openMenu } from './asst-menu.js';
31
31
  import { injectAssistantSidepanelStyles } from './asst-sidepanel-styles.js';
32
32
  import { createMascot, mascotCameoSvg } from '../synabun-mascot.js';
33
- import { createTutorialPreview } from '../ui-tutorial-preview.js';
34
33
 
35
34
  const PANEL_OWNER = 'assistant-sidepanel';
36
35
  const HOST_ID = 'sidepanel';
@@ -652,8 +651,11 @@ export function assistantPanelPeekable() {
652
651
  * Assistant is blocked. restore() puts back the panel's visibility, the docked
653
652
  * peers and the last-active panels, unless the tour ended on its hand-off to a
654
653
  * live tab ('done'): then the panel stays and the tab's composer takes the focus.
654
+ * The preview loads here, before anything of the panel changes: only a tour needs it.
655
655
  */
656
- export function beginAssistantTour({ onPreviewSend = () => {} } = {}) {
656
+ export async function beginAssistantTour({ onPreviewSend = () => {} } = {}) {
657
+ if (assistantBlocked()) return null;
658
+ const { createTutorialPreview } = await import('../ui-tutorial-preview.js');
657
659
  if (assistantBlocked()) return null;
658
660
  ensurePanel();
659
661
  const wasVisible = _visible;